From 47a8d501856c4172682807b0022257e1c9c6b15b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krau=C3=9F=2C=20Josefine?= Date: Tue, 2 Jul 2024 15:45:41 +0200 Subject: [PATCH] method call without using return is a void statement --- src/main/java/TestClass.java | 4 ++++ .../java/abstractSyntaxTree/Statement/BlockStatement.java | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/main/java/TestClass.java b/src/main/java/TestClass.java index 827e3c9..375caa8 100644 --- a/src/main/java/TestClass.java +++ b/src/main/java/TestClass.java @@ -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 { diff --git a/src/main/java/abstractSyntaxTree/Statement/BlockStatement.java b/src/main/java/abstractSyntaxTree/Statement/BlockStatement.java index 34d4122..5f748b7 100644 --- a/src/main/java/abstractSyntaxTree/Statement/BlockStatement.java +++ b/src/main/java/abstractSyntaxTree/Statement/BlockStatement.java @@ -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;