@@ -195,7 +195,11 @@ public static ILconst eval(ImVarArrayAccess e, ProgramState globalState, LocalSt
195195
196196 public static @ Nullable ILconst eval (ImMethodCall mc ,
197197 ProgramState globalState , LocalState localState ) {
198- ILconstObject receiver = globalState .toObject (mc .getReceiver ().evaluate (globalState , localState ));
198+ ImType receiverType = globalState .resolveType (mc .getReceiver ().attrTyp ());
199+ ImClassType receiverClassType = receiverType instanceof ImClassType
200+ ? (ImClassType ) receiverType
201+ : mc .getMethod ().getMethodClass ();
202+ ILconstObject receiver = globalState .toObject (mc .getReceiver ().evaluate (globalState , localState ), receiverClassType );
199203 globalState .assertAllocated (receiver , mc .attrTrace ());
200204 mark (mc , globalState );
201205
@@ -231,7 +235,19 @@ public static ILconst eval(ImVarArrayAccess e, ProgramState globalState, LocalSt
231235
232236
233237 public static ILconst eval (ImMemberAccess ma , ProgramState globalState , LocalState localState ) {
234- ILconstObject receiver = globalState .toObject (ma .getReceiver ().evaluate (globalState , localState ));
238+ ImType receiverType = globalState .resolveType (ma .getReceiver ().attrTyp ());
239+ ImClassType receiverClassType = receiverType instanceof ImClassType ? (ImClassType ) receiverType : null ;
240+ if (receiverClassType == null ) {
241+ de .peeeq .wurstscript .jassIm .Element parent = ma .getVar ().getParent ();
242+ while (parent != null && !(parent instanceof ImClass )) {
243+ parent = parent .getParent ();
244+ }
245+ if (parent instanceof ImClass ) {
246+ receiverClassType = JassIm .ImClassType ((ImClass ) parent , JassIm .ImTypeArguments ());
247+ }
248+ }
249+
250+ ILconstObject receiver = globalState .toObject (ma .getReceiver ().evaluate (globalState , localState ), receiverClassType );
235251 if (receiver == null ) {
236252 throw new InterpreterException (ma .getTrace (), "Null pointer dereference: " + ImPrinter .asString (ma .getReceiver ()));
237253 }
@@ -254,14 +270,14 @@ public static ILconst eval(ImAlloc e, ProgramState globalState, LocalState local
254270
255271 public static ILconst eval (ImDealloc imDealloc , ProgramState globalState ,
256272 LocalState localState ) {
257- ILconstObject obj = globalState .toObject (imDealloc .getObj ().evaluate (globalState , localState ));
273+ ILconstObject obj = globalState .toObject (imDealloc .getObj ().evaluate (globalState , localState ), imDealloc . getClazz () );
258274 globalState .deallocate (obj , imDealloc .getClazz ().getClassDef (), imDealloc .attrTrace ());
259275 return ILconstNull .instance ();
260276 }
261277
262278 public static ILconst eval (ImInstanceof e , ProgramState globalState ,
263279 LocalState localState ) {
264- ILconstObject obj = globalState .toObject (e .getObj ().evaluate (globalState , localState ));
280+ ILconstObject obj = globalState .toObject (e .getObj ().evaluate (globalState , localState ), e . getClazz () );
265281 return ILconstBool .instance (globalState .isInstanceOf (obj , e .getClazz ().getClassDef (), e .attrTrace ()));
266282 }
267283
@@ -272,7 +288,7 @@ public static ILconst eval(ImTypeIdOfClass e,
272288
273289 public static ILconst eval (ImTypeIdOfObj e ,
274290 ProgramState globalState , LocalState localState ) {
275- ILconstObject obj = globalState .toObject (e .getObj ().evaluate (globalState , localState ));
291+ ILconstObject obj = globalState .toObject (e .getObj ().evaluate (globalState , localState ), e . getClazz () );
276292 return new ILconstInt (globalState .getTypeId (obj , e .attrTrace ()));
277293 }
278294
@@ -376,13 +392,14 @@ public ILconst get() {
376392
377393 public static ILaddress evaluateLvalue (ImMemberAccess va , ProgramState globalState , LocalState localState ) {
378394 ImVar v = va .getVar ();
395+ ImType receiverType = globalState .resolveType (va .getReceiver ().attrTyp ());
396+ ImClassType receiverClassType = receiverType instanceof ImClassType ? (ImClassType ) receiverType : null ;
379397 ILconst receiverVal = va .getReceiver ().evaluate (globalState , localState );
380- ILconstObject receiver = globalState .toObject (receiverVal );
381- if (receiver == null && receiverVal instanceof ILconstInt && va . getReceiver (). attrTyp () instanceof ImClassType ) {
398+ ILconstObject receiver = globalState .toObject (receiverVal , receiverClassType );
399+ if (receiver == null && receiverVal instanceof ILconstInt && receiverClassType != null ) {
382400 int objectId = ((ILconstInt ) receiverVal ).getVal ();
383401 if (objectId != 0 ) {
384- receiver = globalState .ensureObject ((ImClassType ) va .getReceiver ().attrTyp (),
385- objectId , va .attrTrace ());
402+ receiver = globalState .ensureObject (receiverClassType , objectId , va .attrTrace ());
386403 }
387404 }
388405 if (receiver == null ) {
@@ -443,7 +460,9 @@ public static ILconst eval(ImTypeVarDispatch e, ProgramState globalState, LocalS
443460
444461 public static ILconst eval (ImCast imCast , ProgramState globalState , LocalState localState ) {
445462 ILconst res = imCast .getExpr ().evaluate (globalState , localState );
446- if (TypesHelper .isIntType (imCast .getToType ())) {
463+ ImType targetType = globalState .resolveType (imCast .getToType ());
464+
465+ if (TypesHelper .isIntType (targetType )) {
447466 if (res instanceof ILconstObject ) {
448467 return ILconstInt .create (((ILconstObject ) res ).getObjectId ());
449468 }
@@ -454,10 +473,10 @@ public static ILconst eval(ImCast imCast, ProgramState globalState, LocalState l
454473 }
455474 }
456475 if (res instanceof ILconstInt ) {
457- if (imCast . getToType () instanceof ImClassType ) {
458- return globalState .getObjectByIndex (((ILconstInt ) res ).getVal ());
476+ if (targetType instanceof ImClassType ) {
477+ return globalState .getObjectByIndex (((ILconstInt ) res ).getVal (), ( ImClassType ) targetType );
459478 }
460- if (imCast . getToType () instanceof IlConstHandle ) {
479+ if (targetType instanceof IlConstHandle ) {
461480 return globalState .getHandleByIndex (((ILconstInt ) res ).getVal ());
462481 }
463482 }
0 commit comments