diff --git a/src/main/java/de/maishai/typedast/typedclass/TypedMethod.java b/src/main/java/de/maishai/typedast/typedclass/TypedMethod.java index e9c4f38..26fcf00 100644 --- a/src/main/java/de/maishai/typedast/typedclass/TypedMethod.java +++ b/src/main/java/de/maishai/typedast/typedclass/TypedMethod.java @@ -20,8 +20,8 @@ public class TypedMethod implements TypedNode { private String name; private Type returnType; private List typedParameters = new ArrayList<>(); - private TypedBlock typedBlock; private List localVariables = new ArrayList<>(); + private TypedBlock typedBlock; public TypedMethod(TypedClass clas, Method unTypedMethod) { convertToTypedMethod(clas, unTypedMethod); @@ -40,12 +40,11 @@ public class TypedMethod implements TypedNode { throw new RuntimeException("Method " + name + " already exists"); }, () -> { }); - - //localVar.put(name, returnType); } public void convertToTypedBlock(TypedClass clas, Method unTypedMethod) { typedBlock = new TypedBlock(clas, unTypedMethod.block()); + typeCheck(clas); } public boolean isLocalVariablePresent(String localVarName) { @@ -67,13 +66,11 @@ public class TypedMethod implements TypedNode { @Override public Type typeCheck(TypedClass clas) { - /* if (localVar.containsKey(name)) { - throw new RuntimeException("Method " + name + " already exists"); + if(returnType != Type.VOID){ + if(typedBlock.typeCheck(clas) != returnType){ + throw new RuntimeException("Method " + name + " must return " + returnType); + } } - localVar.put(name, returnType); - for (TypedParameter typedParameter : typedParameters) { - typedParameter.typeCheck( clas); - }*/ return returnType; }