Bug 17641 – TypeInfo for two identical delegates (or functions) are not equal to each other

Status
RESOLVED
Resolution
INVALID
Severity
major
Priority
P1
Component
druntime
Product
D
Version
D2
Platform
All
OS
Windows
Creation time
2017-07-12T15:55:00Z
Last change time
2017-07-13T22:23:56Z
Assigned to
nobody
Creator
andronkin

Comments

Comment #0 by andronkin — 2017-07-12T15:55:07Z
Example: auto d1 = delegate void(uint a) {}; auto d2 = delegate void(uint a) {}; assert(typeid(d1) is typeid(d2)); // OK But in another case: auto d1 = delegate void(uint a) { writeln(a); }; auto d2 = delegate void(uint a) {}; assert(typeid(d1) is typeid(d2)); // FAILED! Although type hasn't been changed... Also, the string representation of typeid(d1) is "void delegate()", although there must be a "void delegate(uint)".
Comment #1 by ag0aep6g — 2017-07-12T16:20:40Z
(In reply to andronkin from comment #0) > auto d1 = delegate void(uint a) { writeln(a); }; > auto d2 = delegate void(uint a) {}; > > assert(typeid(d1) is typeid(d2)); // FAILED! Although type hasn't been > changed... The type of d1 has changed. Try printing them with `pragma(msg, ...)`: ---- pragma(msg, typeof(d1)); pragma(msg, typeof(d2)); ---- Prints: ---- void delegate(uint a) @safe void delegate(uint a) pure nothrow @nogc @safe ---- You see that d1 is not `pure nothrow @nogc`. Because `writeln` isn't. > Also, the string representation of typeid(d1) is "void delegate()", although > there must be a "void delegate(uint)". Yeah, that looks wrong.
Comment #2 by andronkin — 2017-07-13T14:25:21Z
Thank you, I did not know about this feature. > void delegate(uint) > Yeah, that looks wrong Why is it wrong? This is the correct delegate type definition: void delegate(uint) f = delegate void(uint a) { ... };
Comment #3 by ag0aep6g — 2017-07-13T16:27:17Z
(In reply to andronkin from comment #2) > Thank you, I did not know about this feature. > > > void delegate(uint) > > Yeah, that looks wrong > Why is it wrong? This is the correct delegate type definition: > > void delegate(uint) f = delegate void(uint a) { ... }; "void delegate()" looks wrong. I was agreeing with you.
Comment #4 by andronkin — 2017-07-13T22:23:56Z
Sorry, I misunderstood you.