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;