Bug 10452 – CTFE: Cannot compare delegates with == or 'is'

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-06-23T11:31:00Z
Last change time
2013-07-21T11:38:35Z
Keywords
CTFE, rejects-valid
Assigned to
nobody
Creator
destructionator

Comments

Comment #0 by destructionator — 2013-06-23T11:31:05Z
string foo(bool delegate() bar) { return (bar !is null) ? "0" : "1"; } void main() { enum there = foo(() => true); } test12.d(2): Error: cannot compare __lambda1 at compile time test12.d(7): called from here: foo(bool() { return true; } ) I understand generally not being able to compare pointers in CTFE, but I think is null and !is null should be permitted wherever possible because that's something I do a lot: if(dg is null) return some_default; else return dg(); and it would be cool if it worked in ctfe too. Failed on dmd v2.063
Comment #1 by clugdbug — 2013-07-18T07:18:55Z
This isn't an enhancement, it's a bug. All forms of delegate (null, delegate literal, nested function, struct member, class member) should be comparable with == and 'is'.
Comment #2 by clugdbug — 2013-07-19T00:47:54Z
Comment #3 by github-bugzilla — 2013-07-21T11:38:16Z
Commit pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/48385f97a2604c87fed590a1b091c387183a5167 Fix issue 10452 cannot compare delegates in CTFE Support == and 'is' for delegates.