[Issue 21039] New: `alias this` returns 'null' for ref types when put into array initializer

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Jul 11 21:13:33 UTC 2020


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

          Issue ID: 21039
           Summary: `alias this` returns 'null' for ref types when put
                    into array initializer
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: regression
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: m.rodacki at gmx.de

class Inner {}

class Outer {
  Inner inner; alias inner this;
  this(Inner i) { inner = i; }
}

void main() {
  auto inner = new Inner;
  auto outer = new Outer(new Inner);
  Inner[] inners = [inner, outer];

  assert(inners[0], "first element is null");
  assert(inners[1], "second element is null");
}

---

Output from https://run.dlang.io/is/gfy34l with all d compilers selected

Up to      2.083.1: Success and no output
           2.084.1: Failure with output:
-----
core.exception.AssertError at onlineapp.d(16): second element is null
----------------
??:? _d_assert_msg [0x429018]
onlineapp.d:16 _Dmain [0x427fbb]
-----

           2.085.1: Failure with output:
-----
core.exception.AssertError at onlineapp.d(16): second element is null
----------------
??:? _d_assert_msg [0x42c5ca]
onlineapp.d:16 _Dmain [0x42b53e]
-----

           2.086.1: Failure with output:
-----
core.exception.AssertError at onlineapp.d(16): second element is null
----------------
??:? _d_assert_msg [0x42e27a]
onlineapp.d:16 _Dmain [0x42d1ee]
-----

           2.087.1: Failure with output:
-----
core.exception.AssertError at onlineapp.d(16): second element is null
----------------
??:? _d_assert_msg [0x43040a]
onlineapp.d:16 _Dmain [0x42f23e]
-----

Since      2.088.0: Failure with output:
-----
core.exception.AssertError at onlineapp.d(16): second element is null
----------------
??:? _d_assert_msg [0x430352]
onlineapp.d:16 _Dmain [0x42f2ce]
-----

---

This also appears on dmd v2.092.0 / linux

The issue does appear when the inner type is a class or a pointer. Value types
work fine.

Remotely related but not to be confused with: Issue 19782

--


More information about the Digitalmars-d-bugs mailing list