method call without using return is a void statement

This commit is contained in:
Krauß, Josefine 2024-07-02 15:45:41 +02:00
parent 94b3830561
commit 47a8d50185
2 changed files with 8 additions and 0 deletions

View File

@ -13,6 +13,10 @@ class TestClass {
Example m1(int n){
return new Example();
}
public static void main(String[] args){
TestClass t2 = new TestClass();
t2.meth(2);
}
}
class Example {

View File

@ -65,6 +65,9 @@ public class BlockStatement extends AbstractType implements IStatement {
}
TypeCheckResult typeOfCurrentStatement = statement.typeCheck(methodContext, typeContext, localVars);
if(statement instanceof MethodCallStatementExpression methodCall){
typeOfCurrentStatement.type = "void";
}
if(statement instanceof LocalVarDecl localVarDecl){
localVars.put(localVarDecl.identifier, localVarDecl.type);
}
@ -106,6 +109,7 @@ public class BlockStatement extends AbstractType implements IStatement {
}
if(this.returnType == null)
this.returnType = "void";
result.type = this.returnType;
setTypeCheckResult(result);
return result;