[Issue 19441] alias this causes partial assignment

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Jul 21 14:37:07 UTC 2019


https://issues.dlang.org/show_bug.cgi?id=19441

johanengelen at weka.io changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |johanengelen at weka.io

--- Comment #14 from johanengelen at weka.io ---
How are things now supposed to work with wrapper structs? (or is that
functionality now no longer available?)

```
EntryType arr;
auto getPtr() { return &arr; } 

struct EntryType {
    //int somethingelse; // add for different error message
    bool _state;
    alias _state this;
}

struct S1 {
    @property auto ref entry() { return *getPtr(); }
    alias entry this;
}

void main(){
    S1 s1;
    s1 = true; // Deprecation: Cannot use `alias this` to partially initialize
               // variable `s1` of type `S1`. Use `s1.entry()._state`
}
```

Note that S1 does not store any state. The goal is to use S1 as a transparant
wrapper towards some other data structure.

Weka has the kind of code of the testcase, @Eyal how do you think one should
implement this after this language change?

--


More information about the Digitalmars-d-bugs mailing list