diff --git a/src/main/java/de/maishai/typedast/typedclass/TypedFor.java b/src/main/java/de/maishai/typedast/typedclass/TypedFor.java index 8f8f4cd..ee1bc5a 100644 --- a/src/main/java/de/maishai/typedast/typedclass/TypedFor.java +++ b/src/main/java/de/maishai/typedast/typedclass/TypedFor.java @@ -19,7 +19,6 @@ public class TypedFor implements TypedStatement { private TypedExpression cond; private TypedAssignment inc; private TypedBlock typedBlock; - //TODO: type of block in for loop private Type type; public TypedFor(TypedClass clas, For unTypedFor) { diff --git a/src/main/java/de/maishai/typedast/typedclass/TypedIfElse.java b/src/main/java/de/maishai/typedast/typedclass/TypedIfElse.java index ea06146..0073862 100644 --- a/src/main/java/de/maishai/typedast/typedclass/TypedIfElse.java +++ b/src/main/java/de/maishai/typedast/typedclass/TypedIfElse.java @@ -18,7 +18,6 @@ public class TypedIfElse implements TypedStatement { private TypedExpression typedCon; private TypedBlock ifTypedBlock; private TypedBlock elseTypedBlock; - //TODO: add Type private Type type; public TypedIfElse(TypedClass clas, IfElse unTypedIfElse) { @@ -33,18 +32,24 @@ public class TypedIfElse implements TypedStatement { @Override public Type typeCheck(TypedClass clas) { - +/* if (typedCon.typeCheck(clas) != Type.BOOL) { throw new RuntimeException("If condition must be a boolean"); } if (ifTypedBlock.typeCheck(clas) != Type.VOID) { throw new RuntimeException("If block must be of type void"); } - - //TODO: catch all cases of return when one method has a return type +*/ + //TODO: it still not catching the all cases when return is used if (ifTypedBlock.typeCheck(clas) == elseTypedBlock.typeCheck(clas)) { type = ifTypedBlock.typeCheck(clas); } + if (elseTypedBlock.typeCheck(clas) == Type.VOID) { + type = ifTypedBlock.typeCheck(clas); + } + if (ifTypedBlock.typeCheck(clas) == Type.VOID) { + type = elseTypedBlock.typeCheck(clas); + } return type; }