Comment #0 by snarwin+bugzilla — 2022-09-22T13:14:03Z
As of DMD 2.100.2, the following program fails to compile:
---
alias AliasSeq(Args...) = Args;
struct Foo {
AliasSeq!(int) tuple;
alias slice() = tuple;
}
void main() {
Foo foo;
AliasSeq!(int) t = foo.slice!();
}
---
The error message is:
---
bug.d(10): Error: cannot implicitly convert expression `foo.tuple(__tuple_field_0)` of type `(int)` to `int`
---
In other words, the tuple expression on the right-hand side is not expanded, which causes a type mismatch.
Comment #1 by snarwin+bugzilla — 2022-09-22T13:20:46Z
Note that the following alternatives compile successfully:
---
// OK - use foo.tuple directly
AliasSeq!(int) t = foo.tuple;
---
---
// OK - attach the `this` reference explicitly
AliasSeq!(int) t = __traits(child, foo, Foo.slice!());
---
...although the __traits(child) workaround fails in the general case, when the tuple has more than one element:
---
alias AliasSeq(Args...) = Args;
struct Foo {
AliasSeq!(int, int) tuple;
alias slice() = tuple;
}
void main() {
Foo foo;
AliasSeq!(int, int) t = __traits(child, foo, Foo.slice!());
// Error: expected 2 arguments for `child` but had 3
}
---
Comment #2 by robert.schadek — 2024-12-13T19:24:37Z