[Issue 22943] New: "none of the overloads of `__ctor` are callable using a `immutable` object" error message is backwards
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun Mar 27 03:46:43 UTC 2022
https://issues.dlang.org/show_bug.cgi?id=22943
Issue ID: 22943
Summary: "none of the overloads of `__ctor` are callable using
a `immutable` object" error message is backwards
Product: D
Version: D2
Hardware: x86_64
OS: Linux
Status: NEW
Severity: enhancement
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: andy.pj.hanson at gmail.com
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.
--
More information about the Digitalmars-d-bugs
mailing list