Bug 21039 – `alias this` returns 'null' for ref types when put into array initializer
Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2020-07-11T21:13:33Z
Last change time
2021-11-08T20:45:38Z
Keywords
pull
Assigned to
No Owner
Creator
Michael Rodacki
Comments
Comment #0 by m.rodacki — 2020-07-11T21:13:33Z
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:
-----
[email protected](16): second element is null
----------------
??:? _d_assert_msg [0x429018]
onlineapp.d:16 _Dmain [0x427fbb]
-----
2.085.1: Failure with output:
-----
[email protected](16): second element is null
----------------
??:? _d_assert_msg [0x42c5ca]
onlineapp.d:16 _Dmain [0x42b53e]
-----
2.086.1: Failure with output:
-----
[email protected](16): second element is null
----------------
??:? _d_assert_msg [0x42e27a]
onlineapp.d:16 _Dmain [0x42d1ee]
-----
2.087.1: Failure with output:
-----
[email protected](16): second element is null
----------------
??:? _d_assert_msg [0x43040a]
onlineapp.d:16 _Dmain [0x42f23e]
-----
Since 2.088.0: Failure with output:
-----
[email protected](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
Comment #1 by moonlightsentinel — 2020-07-12T00:20:31Z
@BorisCarvajal created dlang/dmd pull request #13277 "Fix Issue 21039 - `alias this` returns 'null' for ref types when put into array initializer" fixing this issue:
- Fix Issue 21039 - `alias this` returns 'null' for ref types when put into array initializer
https://github.com/dlang/dmd/pull/13277
Comment #3 by dlang-bot — 2021-11-08T09:07:15Z
dlang/dmd pull request #13277 "Fix Issue 21039 - `alias this` returns 'null' for ref types when put into array initializer" was merged into stable:
- 763784c1f2a3a2329facbbbceba6477a51a0fe7d by Boris Carvajal:
Fix Issue 21039 - `alias this` returns 'null' for ref types when put into array initializer
https://github.com/dlang/dmd/pull/13277
Comment #4 by dlang-bot — 2021-11-08T20:45:38Z
dlang/dmd pull request #13279 "Merge `stable` into `master`" was merged into master:
- 904fde46c4bad53ae65d72225d9b5f0c9beb6135 by Boris Carvajal:
Fix Issue 21039 - `alias this` returns 'null' for ref types when put into array initializer
https://github.com/dlang/dmd/pull/13279