www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 15332] New: ICE in e2ir.c: assert(irs->sthis) in

https://issues.dlang.org/show_bug.cgi?id=15332

          Issue ID: 15332
           Summary: ICE in e2ir.c: assert(irs->sthis) in visit(ThisExp),
                    function literal with keyword 'function' calls method
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Keywords: ice
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: eiderdaus gmail.com

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

--
Nov 13 2015