diff --git a/src/main/java/abstractSyntaxTree/StatementExpression/AssignStatementExpression.java b/src/main/java/abstractSyntaxTree/StatementExpression/AssignStatementExpression.java index 2b1b305..fc0cfd2 100644 --- a/src/main/java/abstractSyntaxTree/StatementExpression/AssignStatementExpression.java +++ b/src/main/java/abstractSyntaxTree/StatementExpression/AssignStatementExpression.java @@ -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> typeContext) { + private String getFieldDescriptor(String type, HashMap> 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("\\.", "/");