Updated the typeCheck of TypedIfElse

This commit is contained in:
ahmad 2024-05-12 15:45:18 +02:00
parent 2322d161e6
commit 092cbb5af9
2 changed files with 9 additions and 5 deletions

View File

@ -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) {

View File

@ -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;
}