diff --git a/src/main/java/de/maishai/typedast/typedclass/TypedAssignment.java b/src/main/java/de/maishai/typedast/typedclass/TypedAssignment.java index 2f74d46..c41eca8 100644 --- a/src/main/java/de/maishai/typedast/typedclass/TypedAssignment.java +++ b/src/main/java/de/maishai/typedast/typedclass/TypedAssignment.java @@ -23,6 +23,7 @@ public class TypedAssignment implements TypedStatement { public TypedAssignment(Map localVar, TypedClass clas, Assignment untyped) { convertToTypedAssignment(localVar, clas, untyped); } + public void convertToTypedAssignment(Map localVar, TypedClass clas, Assignment untyped) { varName = untyped.location().id(); value = getKindOfExpression(localVar, clas, untyped.value()); @@ -30,13 +31,20 @@ public class TypedAssignment implements TypedStatement { @Override public Type typeCheck(Map localVar, TypedClass clas) { + Type typeLeft = null; if (!localVar.containsKey(varName)) { - throw new RuntimeException("Variable not declared"); + if(clas.isThereField(varName)){ + typeLeft = clas.getFieldType(varName); + }else { + throw new RuntimeException("Variable not declared"); + } + } else { + typeLeft = localVar.get(varName); } - Type typeLeft = localVar.get(varName); + Type typeRight = value.typeCheck(localVar, clas); - if (typeLeft.equals(typeRight) ) { + if (typeLeft.equals(typeRight)) { type = typeLeft; return typeLeft; }