Bug 22943 – "none of the overloads of `__ctor` are callable using a `immutable` object" error message is backwards

Status
NEW
Severity
minor
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2022-03-27T03:46:43Z
Last change time
2024-12-13T19:21:47Z
Keywords
diagnostic
Assigned to
No Owner
Creator
andy-hanson
Moved to GitHub: dmd#20075 →

Comments

Comment #0 by andy-hanson — 2022-03-27T03:46:43Z
The error message for this code is misleading: ``` immutable(Foo) getFoo(int* a) { return immutable Foo(a); } struct Foo { @disable this(); immutable this(immutable int* a) {} } ``` The error is: ``` a.d(2): Error: none of the overloads of `__ctor` are callable using a `immutable` object a.d(7): Candidate is: `a.Foo.this(immutable(int*) a)` ``` The error message gets the situation backwards. It implies: * That there are no overloads taking an immutable object. Actually, there is only one overload and it takes an immutable object. * That it was called using an immutable object: Actually, a mutable object was used. The real problem is providing a mutable object where an immutable one is expected, but the error message implies that it's the other way around. An ideal error message would be something like: "`a` is an `int*`, but an `immutable int*` was expected." The error message is the same if I provide `string a` as an argument. In that case I don't think it should be talking about qualifiers like `immutable` at all since there is a more obvious type error, Also, this resurfaces a previous issue that the name `__ctor` is appearing in error messsages. https://issues.dlang.org/show_bug.cgi?id=14997 was marked fixed already.
Comment #1 by robert.schadek — 2024-12-13T19:21:47Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/20075 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB