Updated the TypeCheck of TypedAssignement

This commit is contained in:
ahmad 2024-05-11 11:45:47 +02:00
parent cdbb3ae55f
commit 34a20668b6

View File

@ -23,6 +23,7 @@ public class TypedAssignment implements TypedStatement {
public TypedAssignment(Map<String, Type> localVar, TypedClass clas, Assignment untyped) {
convertToTypedAssignment(localVar, clas, untyped);
}
public void convertToTypedAssignment(Map<String, Type> localVar, TypedClass clas, Assignment untyped) {
varName = untyped.location().id();
value = getKindOfExpression(localVar, clas, untyped.value());
@ -30,10 +31,17 @@ public class TypedAssignment implements TypedStatement {
@Override
public Type typeCheck(Map<String, Type> localVar, TypedClass clas) {
Type typeLeft = null;
if (!localVar.containsKey(varName)) {
if(clas.isThereField(varName)){
typeLeft = clas.getFieldType(varName);
}else {
throw new RuntimeException("Variable not declared");
}
Type typeLeft = localVar.get(varName);
} else {
typeLeft = localVar.get(varName);
}
Type typeRight = value.typeCheck(localVar, clas);
if (typeLeft.equals(typeRight)) {