[Issue 21674] New: [REG v2.086] `alias this` triggers wrong deprecation message on function call
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue Mar 2 02:50:17 UTC 2021
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 at puremagic.com
Reporter: pro.mathias.lang at 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).
--
More information about the Digitalmars-d-bugs
mailing list