Fixed Error with InstVars in Assign, where the class in which the field was going to be in was not correct, due to the InstVar parameter not being set and it being treated as a localVar

This commit is contained in:
Jochen Seyfried 2024-07-03 07:49:39 +02:00
parent 5dae167443
commit 88bcfa5fa3

View File

@ -93,7 +93,7 @@ public class AssignStatementExpression extends AbstractType implements IExpressi
// Call the codeGen on the right expression which will push the value of the right expression onto the stack
right.codeGen(mv, localVars, typeContext, methodContext);
// Get the field descriptor
String descriptor = getFieldDescriptor(fieldType, typeContext);
String descriptor = getFieldDescriptor(fieldType, typeContext, varName, thisClass);
// Store the value in the field
mv.visitFieldInsn(Opcodes.PUTFIELD, thisClass, varName, descriptor);
return;
@ -146,14 +146,14 @@ public class AssignStatementExpression extends AbstractType implements IExpressi
String fieldType = typeContext.get(instVar.thisClass).get(instVar.fieldName);
// Get the field descriptor
String descriptor = getFieldDescriptor(fieldType, typeContext);
String descriptor = getFieldDescriptor(fieldType, typeContext, instVar.fieldName, instVar.thisClass);
// Store the value in the field
mv.visitFieldInsn(Opcodes.PUTFIELD, instVar.thisClass, instVar.fieldName, descriptor);
}
}
private String getFieldDescriptor(String type, HashMap<String, HashMap<String, String>> typeContext) {
private String getFieldDescriptor(String type, HashMap<String, HashMap<String, String>> typeContext, String varName, String classToSearchFieldIn) {
StringBuilder descriptor = new StringBuilder();
switch (type) {
case "int":
@ -163,7 +163,7 @@ public class AssignStatementExpression extends AbstractType implements IExpressi
case "char":
return "C";
default: {
String fullReturnType = typeContext.get(instVar.thisClass).get(instVar.fieldName);
String fullReturnType = typeContext.get(classToSearchFieldIn).get(varName);
// If it is a class reference replace the "." with "/" and return it
if (type.contains(".")) fullReturnType = fullReturnType.replaceAll("\\.", "/");