From 31d57c8ba9f87e931256bc3f49090da67935460c Mon Sep 17 00:00:00 2001 From: ahmad Date: Sat, 11 May 2024 13:54:30 +0200 Subject: [PATCH] update the typeCheck of TypedReturn --- .../typedast/typedclass/TypedReturn.java | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/main/java/de/maishai/typedast/typedclass/TypedReturn.java b/src/main/java/de/maishai/typedast/typedclass/TypedReturn.java index 86b9a0b..83ba604 100644 --- a/src/main/java/de/maishai/typedast/typedclass/TypedReturn.java +++ b/src/main/java/de/maishai/typedast/typedclass/TypedReturn.java @@ -28,18 +28,14 @@ public class TypedReturn implements TypedStatement { @Override public Type typeCheck(Map localVar, TypedClass clas) { - //TODO: not localvar - for(var typedMethod : clas.getTypedMethods()) { - if(localVar.containsKey(typedMethod.getName())) { - if(typedMethod.getReturnType().getKind() != this.type.getKind()) { - //TODO: exception auslagern - StringBuilder exp = new StringBuilder(); - exp.append("\nMismatched return type: "); - exp.append("\nExpected: ").append(typedMethod.getReturnType().getKind()); - exp.append("\nActual: ").append(this.type.getKind()); - exp.append("\nMethod name: ").append(typedMethod.getName()); - throw new RuntimeException(exp.toString()); - } + if(clas.isCurrentMethodPresent()){ + if(clas.getCurrentMethod().getReturnType().getKind() != this.type.getKind()){ + StringBuilder exp = new StringBuilder(); + exp.append("\nMismatched return type: "); + exp.append("\nExpected: ").append(clas.getCurrentMethod().getReturnType().getKind()); + exp.append("\nActual: ").append(this.type.getKind()); + exp.append("\nMethod name: ").append(clas.getCurrentMethod().getName()); + throw new RuntimeException(exp.toString()); } } return type;