Bug 15225 – cannot overload directly aliased function literals

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-10-19T15:06:54Z
Last change time
2020-12-21T02:15:41Z
Keywords
pull, rejects-valid
Assigned to
No Owner
Creator
Kenji Hara

Comments

Comment #0 by k.hara.pg — 2015-10-19T15:06:54Z
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)
Comment #1 by dlang-bugzilla — 2015-10-27T09:11:07Z
(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).
Comment #2 by dlang-bugzilla — 2017-07-03T20:40:19Z
(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.
Comment #3 by ag0aep6g — 2018-02-25T12:19:53Z
*** Issue 16099 has been marked as a duplicate of this issue. ***
Comment #4 by b2.temp — 2019-04-22T23:34:07Z
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.
Comment #5 by dlang-bot — 2020-12-21T01:27:14Z
@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
Comment #6 by dlang-bot — 2020-12-21T02:15:41Z
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