www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 21674] New: [REG v2.086] `alias this` triggers wrong


          Issue ID: 21674
           Summary: [REG v2.086] `alias this` triggers wrong deprecation
                    message on function call
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Keywords: rejects-valid
          Severity: regression
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: pro.mathias.lang gmail.com

Originally posted as a comment on the PR that introduced the regression:

struct Module
    CachedString data;

struct CachedString
    private size_t len;

    this (string data) { this.len = data.length; }
    public string str () const { return null; }
    public void str (string value) { this.len = value.length; assert(0); }

    alias str this;

void main ()
    Module m;
    m.data = "Hello World";

I added an `assert(0);` to confirm that `str` is being called (and it is).
This triggers the following deprecation message:
dep.d(20): Deprecation: Cannot use `alias this` to partially initialize
variable `m.data` of type `CachedString`. Use `m.data.str`

This message is wrong, the `str` setter gets called (as expected).

Mar 01 2021