www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 21780] New: alias this preferred over immutable conversion

https://issues.dlang.org/show_bug.cgi?id=21780

          Issue ID: 21780
           Summary: alias this preferred over immutable conversion even if
                    alias this is deprecated and de is on
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: trivial
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: default_357-line yahoo.de

Consider the following code:

immutable struct S { }

struct Nullable {
    S get_() { return S.init; }
    deprecated alias get_ this;
}

void foo(immutable Nullable) { }
void foo(immutable S) { }

void main() {
    foo(Nullable());
}

So `Nullable()` is implicitly convertible to `immutable Nullable` without
hitting the "alias this". And yet, DMD will prefer the deprecated conversion
even if `-de` is on, erroring with

Deprecation: `alias get_ this` is deprecated

This despite the fact that removing the `alias get_ this` will allow the code
to compile.

Marked as trivial because as you can guess from the struct name, this issue
will solve itself "naturally" when 2.097 releases. :)

--
Mar 29 2021