digitalmars.D.bugs - [Issue 21674] New: [REG v2.086] `alias this` triggers wrong
- d-bugmail puremagic.com (44/44) Mar 01 2021 https://issues.dlang.org/show_bug.cgi?id=21674
https://issues.dlang.org/show_bug.cgi?id=21674 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: https://github.com/dlang/dmd/pull/9323#issuecomment-686852776 ``` 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