Bug 15347 – error message for converting return value with ctor/dtor is horrible

Status
NEW
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-11-16T22:47:52Z
Last change time
2024-12-13T18:45:50Z
Keywords
diagnostic
Assigned to
No Owner
Creator
Steven Schveighoffer
Moved to GitHub: dmd#19070 →

Comments

Comment #0 by schveiguy — 2015-11-16T22:47:52Z
Simple example: struct S(T) { T *t; immutable(S) foo(T* x) { return S(x);} } S!int s; The error message is as follows: Error: cannot implicitly convert expression (S(x)) of type S!int to immutable(S!int) Reasonable, straightforward message. But it starts breaking down as we add ctor and dtor: struct S(T) { T *t; this(T *x) { t = x;} immutable(S) foo(T* x) { return S(x);} } Error: cannot implicitly convert expression (S(null).this(x)) of type S!int to immutable(S!int) Not sure where the S(null).this(x) comes from. Add a dtor and it's even worse: struct S(T) { T *t; this(T *x) { t = x;} ~this() {} immutable(S) foo(T* x) { return S(x);} } Error: cannot implicitly convert expression (( S!int __slS51 = S(null); , __slS51).this(x)) of type S!int to immutable(S!int) That carriage return is actually in the output. I don't even think that's valid D code (semicolon followed by comma). All three of these should look like the first one. Note that just a dtor does not affect the output. Tested as far back as 2.067.1
Comment #1 by razvan.nitu1305 — 2022-10-13T08:27:33Z
The destructor one has been fixed so that compiler internals are not spilled out anymore: "cannot implicitly convert expression (S(x)) of type S!int to immutable(S!int)". However, the constructor one still outputs `S(null).this(x)`. That is mainly because that is what the compiler rewrites `S(x)` so that it is processed as a method call. Not sure if this could be improved.
Comment #2 by robert.schadek — 2024-12-13T18:45:50Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19070 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB