update the typeCheck of TypedReturn

This commit is contained in:
ahmad 2024-05-11 13:54:30 +02:00
parent e49691ff29
commit 31d57c8ba9

View File

@ -28,20 +28,16 @@ public class TypedReturn implements TypedStatement {
@Override @Override
public Type typeCheck(Map<String, Type> localVar, TypedClass clas) { public Type typeCheck(Map<String, Type> localVar, TypedClass clas) {
//TODO: not localvar if(clas.isCurrentMethodPresent()){
for(var typedMethod : clas.getTypedMethods()) { if(clas.getCurrentMethod().getReturnType().getKind() != this.type.getKind()){
if(localVar.containsKey(typedMethod.getName())) {
if(typedMethod.getReturnType().getKind() != this.type.getKind()) {
//TODO: exception auslagern
StringBuilder exp = new StringBuilder(); StringBuilder exp = new StringBuilder();
exp.append("\nMismatched return type: "); exp.append("\nMismatched return type: ");
exp.append("\nExpected: ").append(typedMethod.getReturnType().getKind()); exp.append("\nExpected: ").append(clas.getCurrentMethod().getReturnType().getKind());
exp.append("\nActual: ").append(this.type.getKind()); exp.append("\nActual: ").append(this.type.getKind());
exp.append("\nMethod name: ").append(typedMethod.getName()); exp.append("\nMethod name: ").append(clas.getCurrentMethod().getName());
throw new RuntimeException(exp.toString()); throw new RuntimeException(exp.toString());
} }
} }
}
return type; return type;
} }