Bug 15332 – ICE in e2ir.c: assert(irs->sthis) in visit(ThisExp), function literal with keyword 'function' calls method
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-11-14T01:16:00Z
Last change time
2016-02-02T03:02:17Z
Keywords
ice, pull
Assigned to
nobody
Creator
eiderdaus
Comments
Comment #0 by eiderdaus — 2015-11-14T01:16:03Z
Reduced test case:
class MyClass {
int myMethod() { return 5; }
this() {
int a = function() { return myMethod; }();
}
}
On compiling this with dmd 64-bit, v2.069.0, I get this internal compiler error:
dmd: e2ir.c:1209: virtual void toElem(Expression*,
IRState*)::ToElemVisitor::visit(ThisExp*):
Assertion `irs->sthis' failed.
Aborted
The code sample compiles with no problems when I remove the keyword 'function', turning the 4th line into:
int a = () { return myMethod; }();
A different way of getting the code sample to compile is to make myMethod a non-method function outside of the class, or to remove myMethod altogether and replace the call to myMethod by the literal 5:
int a = function() { return 5; }();
-- Simon
Comment #1 by eiderdaus — 2015-11-14T01:59:23Z
Speculation: 'function' doesn't allow to refer to information outside of the literal's body (here, the 'this' pointer), unlike 'delegate'. Removing the keyword makes my literal a delegate, which becomes legal D. dmd doesn't notice the illegal referral to outside information at first, but eventually ends up with 'this' being a null pointer, failing the assert in e2ir.c.