D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 20470 - accessing an AliasSeq tuple loses `this`
Summary: accessing an AliasSeq tuple loses `this`
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 enhancement
Assignee: No Owner
URL:
Keywords: pull
Depends on:
Blocks:
 
Reported: 2019-12-30 14:35 UTC by Suleyman Sahmi (سليمان السهمي)
Modified: 2020-03-10 15:18 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Suleyman Sahmi (سليمان السهمي) 2019-12-30 14:35:51 UTC
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 Suleyman Sahmi (سليمان السهمي) 2019-12-31 06:02:55 UTC
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 Dlang Bot 2020-01-01 14:49:01 UTC
@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 Dlang Bot 2020-03-10 15:18:23 UTC
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