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