Bug 13189 – `alias this` is not transitive

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Linux
Creation time
2014-07-22T17:43:53Z
Last change time
2024-12-13T18:22:40Z
Assigned to
No Owner
Creator
hsteoh
See also
https://issues.dlang.org/show_bug.cgi?id=5380
Moved to GitHub: dmd#18855 →

Comments

Comment #0 by hsteoh — 2014-07-22T17:43:53Z
Code: ------ import std.typecons : TypeTuple; struct S { int x; int y; } struct T { S s; alias s this; } static assert(is(typeof(T.init.x))); static assert(is(typeof(T.init.y))); struct U { T t; //alias x = t.x; // <-- FAIL alias x = t.s.x; // <-- OK } void main() { } ------ The line marked "FAIL" does not compile if uncommented: ------ test.d(18): Error: need 'this' for 's' of type 'S' ------ The following line works. But it should not be necessary to specify '.s' here, since the static asserts before the definition of struct U show that '.x' and '.y' can be accessed directly given an instance of T, due to the `alias s this`. So it should be possible to alias the symbol directly without needing to specify '.s'.
Comment #1 by john.michael.hall — 2020-06-04T19:38:12Z
When I compile below I get the error: "onlineapp.d(17): Error: no property x for type onlineapp.T" struct S { int x; int y; } struct T { S s; alias s this; } static assert(is(typeof(T.init.x))); static assert(is(typeof(T.init.y))); struct U { T t; alias x = t.x; // <-- FAIL alias y = t.s.x; // <-- OK } void main() { }
Comment #2 by robert.schadek — 2024-12-13T18:22:40Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18855 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB