Bug 17710 – Undefined behaviour and non-working casting of overloaded methods invoking overloaded delegates

Status
NEW
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Linux
Creation time
2017-08-01T12:12:18Z
Last change time
2024-12-13T18:53:47Z
Assigned to
No Owner
Creator
KML NXW
Moved to GitHub: dmd#19294 →

Attachments

IDFilenameSummaryContent-TypeSize
1652code.dSample code presenting the bug.application/x-dsrc471

Comments

Comment #0 by kamil.subzda — 2017-08-01T12:12:18Z
Created attachment 1652 Sample code presenting the bug. Sample code to present the case (also in the attachment): // alias BoolFirst = void delegate(bool b, string s); alias StringFirst = void delegate(string s, bool b); class Caller { void call(BoolFirst bs) { bs(true, "text"); } void call(StringFirst sb) { sb("text", true); } } class Writer { import std.stdio; void write(bool b, string s) { writeln("bool+string:", b, "/", s); } void write(string s, bool b) { writeln("string+bool:", s, "/", b); } } void main() { new Caller().call(&new Writer().write); } // The call in main() is ambiguous, but nevertheless the code compiles and the program runs the "string+bool" variant. Swapping write() methods in the source file causes calling "bool+string" variant. Casting call(cast(StringFirst) &w.write) compiles, although is not necessary, because not casting works the same way, but casting call(cast(BoolFirst) &w.write) - which should help in calling bool+string variant - does not compile, and the compiler says that "Caller.call called with argument types (void delegate(bool b, string s)) matches both (...)", which is untrue. Moreover, swapping write() methods again causes the exact opposite behaviour: cast(BoolFirst) compiles, but is useless, and cast(StringFirst) does not compile at all.
Comment #1 by robert.schadek — 2024-12-13T18:53:47Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19294 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB