Bug 14286 – `alias this` not considered sub-typing in is() expression

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2015-03-15T17:02:53Z
Last change time
2024-12-13T18:41:14Z
Assigned to
No Owner
Creator
Marc Schütz
Moved to GitHub: dmd#18958 →

Comments

Comment #0 by schuetzm — 2015-03-15T17:02:53Z
This works: class V(string s) { } class S(int U) : V!"xyz" { } void main() { S!10 a; static if(is(typeof(a) : V!Args, Args...)) pragma(msg, Args); else pragma(msg, "nope"); } This doesn't: struct V(string s) { } struct S(int U) { V!"xyz" x; alias x this; } void main() { S!10 a; static if(is(typeof(a) : V!Args, Args...)) pragma(msg, Args); else pragma(msg, "nope"); } As `alias this` should work wherever sub-typing works, I guess this is a bug.
Comment #1 by john.michael.hall — 2018-03-22T19:35:07Z
The issue seems to be related to templated variables in alias this. Not an issue without templates. struct V { } struct S { V x; alias x this; } void main() { S a; static if(is(typeof(a) : V)) pragma(msg, "yep"); //prints "yep" else pragma(msg, "nope"); }
Comment #2 by simen.kjaras — 2018-03-23T09:15:11Z
Indeed. For clarification: the inner struct can be templated, the outer cannot: struct Inner1 {} struct Inner2() {} struct Outer1 { Inner1 a; alias a this; } struct Outer2 { Inner2!() a; alias a this; } struct Outer3() { Inner1 a; alias a this; } struct Outer4() { Inner2!() a; alias a this; } // Non-template outer struct: static assert( is(Outer1 : Inner1)); static assert( is(Outer2 : Inner2!())); // Templated outer struct: static assert(!is(Outer3 : Inner1)); static assert(!is(Outer4 : Inner2!()));
Comment #3 by robert.schadek — 2024-12-13T18:41:14Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18958 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB