Testcase:
```
struct A {
void foo(int delegate(int)) { }
void foo(int delegate(int) nothrow) const { } // const
void bug() {
foo( delegate int(int k) { return 1;} );
}
}
```
Compilation with dlang2.098 succeeds.
Compilation with dlang2.099 errors with:
```
<source>(7): Error: `example.A.foo` called with argument types `(int delegate(int k) pure nothrow @nogc @safe)` matches both:
<source>(2): `example.A.foo(int delegate(int) _param_0)`
and:
<source>(4): `example.A.foo(int delegate(int) nothrow _param_0) const`
```
Because `bug` is not const, I would expect that only the non-const `foo` is a candidate. If `nothrow` is removed, indeed that is what is called.
Note: replacing `delegate` with `function` errors on all compilers at least back to dlang2.071.
Comment #1 by johanengelen — 2022-07-29T23:33:25Z
I'm not 100% what should happen here, so please think very carefully about if this is valid or invalid code. If valid, what function call should happen. (please think for more than 5 minutes)
Comment #2 by ibuclaw — 2022-12-20T20:28:48Z
This is the introducing change: https://github.com/dlang/dmd/pull/13267
There used to be a test in xtest46.d which did exactly what you're doing here, but that was changed as part of the linked PR to fix...
Comment #3 by dfj1esp02 — 2022-12-21T13:55:32Z
Looks like D doesn't allow such overloads.
---
struct A
{
int a;
void b(const int[]);
void b(int[]) const;
}
void e()
{
int[] g;
A a;
a.b(g);
}
---
Up to 2.063: Failure with output:
onlineapp.d(11): Error: function onlineapp.A.b called with argument types:
((int[]))
matches both:
onlineapp.d(4): onlineapp.A.b(const(int[]))
and:
onlineapp.d(5): onlineapp.A.b(int[])
Comment #4 by robert.schadek — 2024-12-13T19:24:01Z