method call without using return is a void statement
This commit is contained in:
parent
94b3830561
commit
47a8d50185
@ -13,6 +13,10 @@ class TestClass {
|
|||||||
Example m1(int n){
|
Example m1(int n){
|
||||||
return new Example();
|
return new Example();
|
||||||
}
|
}
|
||||||
|
public static void main(String[] args){
|
||||||
|
TestClass t2 = new TestClass();
|
||||||
|
t2.meth(2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Example {
|
class Example {
|
||||||
|
@ -65,6 +65,9 @@ public class BlockStatement extends AbstractType implements IStatement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TypeCheckResult typeOfCurrentStatement = statement.typeCheck(methodContext, typeContext, localVars);
|
TypeCheckResult typeOfCurrentStatement = statement.typeCheck(methodContext, typeContext, localVars);
|
||||||
|
if(statement instanceof MethodCallStatementExpression methodCall){
|
||||||
|
typeOfCurrentStatement.type = "void";
|
||||||
|
}
|
||||||
if(statement instanceof LocalVarDecl localVarDecl){
|
if(statement instanceof LocalVarDecl localVarDecl){
|
||||||
localVars.put(localVarDecl.identifier, localVarDecl.type);
|
localVars.put(localVarDecl.identifier, localVarDecl.type);
|
||||||
}
|
}
|
||||||
@ -106,6 +109,7 @@ public class BlockStatement extends AbstractType implements IStatement {
|
|||||||
}
|
}
|
||||||
if(this.returnType == null)
|
if(this.returnType == null)
|
||||||
this.returnType = "void";
|
this.returnType = "void";
|
||||||
|
|
||||||
result.type = this.returnType;
|
result.type = this.returnType;
|
||||||
setTypeCheckResult(result);
|
setTypeCheckResult(result);
|
||||||
return result;
|
return result;
|
||||||
|
Loading…
Reference in New Issue
Block a user