Bug 20470 – accessing an AliasSeq tuple loses `this`
Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2019-12-30T14:35:51Z
Last change time
2020-03-10T15:18:23Z
Keywords
pull
Assigned to
No Owner
Creator
Suleyman Sahmi (سليمان السهمي)
Comments
Comment #0 by sahmi.soulaimane — 2019-12-30T14:35:51Z
Test case:
```
template AliasSeq(Args...) { alias Args AliasSeq; }
struct S
{
int a, b;
alias AliasSeq!(b, a) expandReverse;
}
unittest
{
S obj;
int a, b;
obj.expandReverse = AliasSeq!(b, a); // error: need `this` for`b` ...
}
```
The only option currently where accessing a tuple doesn't lose `this` is the following solution:
```
template AliasSeq(Args...) { alias Args AliasSeq; }
struct S
{
AliasSeq!(int, int) expand; // this has worked since forever it seems
}
unittest
{
S obj;
int a, b;
obj.expand = AliasSeq!(a, b);
}
```
Comment #1 by sahmi.soulaimane — 2019-12-31T06:02:55Z
If a member tuple contains functions and this tuple is unpacked with a foreach statement then there is current usage that would break if `this` is preserved.
```
alias AliasSeq(Args...) = Args;
struct S
{
void f() {}
alias funcs = AliasSeq!(f);
}
unittest
{
S obj;
foreach (f; obj.funcs) // obj.funcs is expanded into S.f not obj.f
pragma(msg, typeof(f));
}
```
Comment #2 by dlang-bot — 2020-01-01T14:49:01Z
@SSoulaimane updated dlang/dmd pull request #10702 "Fix issue 20470 - Keep `this` when accessing tuple members" fixing this issue:
- Fix issue 20470 - Keep `this` when accessing tuple members
Expand `m.tuple(a, b)` into `tuple(m.a, m.b)`
https://github.com/dlang/dmd/pull/10702
Comment #3 by dlang-bot — 2020-03-10T15:18:23Z
dlang/dmd pull request #10702 "Fix issue 20470 - Keep `this` when accessing tuple members" was merged into master:
- 33941f0400ed0842cbfc68bd43295b948691a5f8 by سليمان السهمي (Suleyman Sahmi):
Fix issue 20470 - Keep `this` when accessing tuple members
Expand `m.tuple(a, b)` into `tuple(m.a, m.b)`
https://github.com/dlang/dmd/pull/10702