From 34a20668b64528eb442a3f79f02b759cec0e3923 Mon Sep 17 00:00:00 2001 From: ahmad Date: Sat, 11 May 2024 11:45:47 +0200 Subject: [PATCH] Updated the TypeCheck of TypedAssignement --- .../typedast/typedclass/TypedAssignment.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) 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; }