Bug 20073 – Wrong implicit conversion for return type
Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2019-07-22T18:54:33Z
Last change time
2019-07-25T02:19:48Z
Keywords
accepts-invalid, industry, pull
Assigned to
No Owner
Creator
Eyal
Comments
Comment #0 by eyal — 2019-07-22T18:54:33Z
It seems that some weird interaction between "alias this", "inout" and implicit return conversions is incorrectly allowing a conversion from an S instance, which isn't immutable, to an immutable(char)[].
Note the assignment is (correctly) rejected but the return is (incorrectly) allowed:
struct S {
char[10] x;
auto slice() inout { return x[0 .. 10]; }
alias slice this;
}
string test() {
S s;
string str = s; // cannot implicitly convert expression `s` of type `S` to `string`
return s; // and suddenly we can!
}
I'd expect both the assignment and return to fail.
Comment #1 by dlang-bot — 2019-07-24T13:05:54Z
@RazvanN7 created dlang/dmd pull request #10216 "Fix Issue 20073 - Wrong implicit conversion for return type" fixing this issue:
- Fix Issue 20073 - Wrong implicit conversion for return type
https://github.com/dlang/dmd/pull/10216
Comment #2 by dlang-bot — 2019-07-25T02:19:48Z
dlang/dmd pull request #10216 "Fix Issue 20073 - Wrong implicit conversion for return type" was merged into master:
- 6b672cbcde0ef47d0bc56731dda8a480f00e1468 by RazvanN7:
Fix Issue 20073 - Wrong implicit conversion for return type
https://github.com/dlang/dmd/pull/10216