Test case: --- alias foo = (int x) => x; alias foo = (string x) => x; void main() { foo(1); foo("a"); // line 7 } Output: --- test.d(7): Error: function literal __lambda4 (int x) is not callable using argument types (string)
(In reply to Kenji Hara from comment #0) > alias foo = (int x) => x; > alias foo = (string x) => x; This syntax doesn't work in released DMD versions, but if I replace it with: alias I(alias X) = X; alias foo = I!((int x) => x); alias foo = I!((string x) => x); then compilation succeeds (though then I get a linker error).
(In reply to Vladimir Panteleev from comment #1) > then compilation succeeds (though then I get a linker error). Linking succeeds since 2.071.0 (fixed by https://github.com/dlang/dmd/pull/5523). Kenji's example still doesn't compile.
*** Issue 16099 has been marked as a duplicate of this issue. ***
A second level of aliasing is required: alias lambda1 = (int x) => x; alias lambda2 = (string x) => x; alias lambda = lambda1; alias lambda = lambda2; void main() { auto r0 = lambda(1); auto r1 = lambda("a"); } But this should not be the case since, as found in one of the duplicated reports, this works fine if you replace lambda1/lambda2 by standard functions. It turns out that the problem is that when doing aliasSemantic() for lambda1, its `.overnext` member is null. so without the second level of aliasing, the first match is always used. It's quite possible that the semantic is done in the wrong order., e.g the call is resolved before that the overload set is built.
@BorisCarvajal created dlang/dmd pull request #12041 "Fix Issue 15225 - cannot overload directly aliased function literals" fixing this issue: - Fix Issue 15225 - cannot overload directly aliased function literals https://github.com/dlang/dmd/pull/12041
dlang/dmd pull request #12041 "Fix Issue 15225 - cannot overload directly aliased function literals" was merged into master: - f04ab2275a948b3b4ea858523b326db971201eb4 by Boris Carvajal: Fix Issue 15225 - cannot overload directly aliased function literals https://github.com/dlang/dmd/pull/12041