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