www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22943] New: "none of the overloads of `__ctor` are callable

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 puremagic.com
          Reporter: andy.pj.hanson 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.

--
Mar 26 2022