[Issue 21674] [REG v2.086] `alias this` triggers wrong deprecation message on function call

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Feb 17 09:38:09 UTC 2022


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

Iain Buclaw <ibuclaw at gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ibuclaw at gdcproject.org

--- Comment #6 from Iain Buclaw <ibuclaw at gdcproject.org> ---
Supplementary test for this issue.
---
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`
}
---

This happens because op_overload is recursive, i.e:

op_overload(e=`s1 = true`, ad1=`S1`)
-> op_overload(e=`s1.entry()`, ad1=`EntryType`)
  -> check: EntryType.members == 1 && typeof(EntryType[0]) == typeof(true)
    -> TRUE: return e=`s1.entry()._state = true`
-> check: S1.members == 1 && typeof(S1[0]) == typeof(true)
  -> FALSE: deprecation warning

--


More information about the Digitalmars-d-bugs mailing list