[Issue 20073] New: Wrong implicit conversion for return type
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Jul 22 18:54:33 UTC 2019
https://issues.dlang.org/show_bug.cgi?id=20073
Issue ID: 20073
Summary: Wrong implicit conversion for return type
Product: D
Version: D2
Hardware: All
URL: http://dlang.org/
OS: All
Status: NEW
Severity: major
Priority: P3
Component: dmd
Assignee: nobody at puremagic.com
Reporter: eyal at weka.io
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.
--
More information about the Digitalmars-d-bugs
mailing list