Buggy code:
public ArrayList < Expression > args ; public ArrayList < String > dirs ; public DataType retType ; public boolean index = false ; public Function fn ; public LookupFunction ( String name , ArrayList < Expression > args , DataType retType , ArrayList < String > dirs ) { } public LookupFunction ( CompileData cd , Range rn , String name , DataType retType , ArrayList < String > dirs , String ... args ) { } public FunctionCall toFuncCall ( ) { } public CompileLookup . LookupFunction cloneFunc ( ) { } } public static Expression mathOp ( CompileData cd , String name , String retVar , Object ret , String [ ] sargs , Object [ ] args ) { } public static CompileLookup . LookupNode getLookupTree ( CompileData cd ) { } public static CompileLookup . LookupNode getLookupTree ( CompileData cd , CompileLookup . LookupNode node ) { } public static CompileLookup . LookupNode parseArgs ( CompileData cd , Object ... args ) { } public static Expression toExpr ( CompileData cd , String retVar , CompileLookup . LookupNode node ) { } public static Expression rvalLookup ( CompileData cd , String retVar , Object ... args ) { } public static CompileLookup . LookupNode getType ( CompileLookup . LookupNode tree , String name ) { } public static CompileLookup . LookupNode lookup ( CompileData cd , Object ... args ) { CompileLookup . LookupNode rawtree = CompileLookup . parseArgs ( cd , args ) ; CompileLookup . LookupNode rawnode = rawtree ; CompileLookup . LookupNode lookupTree = CompileLookup . getLookupTree ( cd ) ; ArrayList < CompileLookup . LookupNode > lookupNodes = new ArrayList < > ( ) ; lookupNodes . add ( lookupTree ) ; ArrayList < CompileLookup . LookupNode > nodes = new ArrayList < > ( ) ; nodes . add ( CompileLookup . LookupNode . root ( null ) ) ; while ( true ) { if ( rawnode . c . isEmpty ( ) ) { break ; } rawnode = ( ( CompileLookup . LookupNode ) ( rawnode . c . get ( 0 ) ) ) ; ArrayList < CompileLookup . LookupNode > newLookupNodes = new ArrayList < > ( ) ; ArrayList < CompileLookup . LookupNode > newNodes = new ArrayList < > ( ) ; if ( ( rawnode . type ) == ( CompileLookup . LookupType . EXPR ) ) { int i = 0 ; for ( CompileLookup . LookupNode node : lookupNodes ) { if ( ( node . type ) == ( CompileLookup . LookupType . ROOT ) ) { CompileLookup . LookupNode child = nodes . get ( i ) ; node = CompileLookup . getType ( lookupTree , ( ( Expression ) ( rawnode . data ) ) . type . type . name ) ; newLookupNodes . add ( node ) ; CompileLookup . LookupNode newNode = rawnode . cloneNode ( ) ; child . c . add ( newNode ) ; newNode . p = child ; newNodes . add ( newNode ) ; } i ++ ; } } else { int i = 0 ; for ( CompileLookup . LookupNode lookupNode : lookupNodes ) { CompileLookup . LookupNode node = nodes . get ( i ) ; for ( CompileLookup . LookupNode child : ( ( ArrayList < CompileLookup . LookupNode > ) ( lookupNode . c ) ) ) { switch ( rawnode . type ) { case RAWSTR : if ( ( rawnode . match ) == null ? false : rawnode . match . equals ( child . match ) ) { CompileLookup . LookupNode newNode = child . cloneNode ( ) ; node . c . add ( newNode ) ; newNode . p = node ; newNodes . add ( newNode ) ; newLookupNodes . add ( child ) ; } break ; case RAWCALL : if ( ( rawnode . match . equals ( child . match ) ) && ( ( ( child . type ) == ( CompileLookup . LookupType . FUNC ) ) || ( ( child . type ) == ( CompileLookup . LookupType . METHOD ) ) ) ) { CompileLookup . LookupFunction fcall = ( ( CompileLookup . LookupFunction ) ( rawnode . data ) ) ; <START_BUG> if ( ( node . type ) != ( CompileLookup . LookupType . ROOT ) ) { <END_BUG> fcall . args . add ( 0 , new Expression ( ) ) ; fcall . args . get ( 0 ) . type = node . dataType ; } FunctionCall fcall2 = fcall . toFuncCall ( ) ; if ( cd . pkg . isFunctionCallCompatible ( ( ( Function ) ( child . data ) ) , fcall2 ) ) { CompileLookup . LookupNode newNode = child . cloneNode ( ) ; node . c . add ( newNode ) ; newNode . p = node ; fcall . fn = ( ( Function ) ( child . data ) ) ; newNode . data = fcall ; newNodes . add ( newNode ) ; newLookupNodes . add ( child ) ; } } break ; } } i ++ ; } } ArrayList < CompileLookup . LookupNode > oldLookupNodes = lookupNodes ; ArrayList < CompileLookup . LookupNode > oldNodes = nodes ; lookupNodes = newLookupNodes ; nodes = newNodes ; if ( nodes . isEmpty ( ) ) { int j = 0 ; for ( CompileLookup . LookupNode child : oldLookupNodes ) { CompileLookup . LookupNode node = oldNodes . get ( j ) ;

Fix:
if ( ( lookupNode . type ) == ( CompileLookup . LookupType . TYPE ) ) {