diff --git a/src/main/java/abstractSyntaxTree/Class/MethodDecl.java b/src/main/java/abstractSyntaxTree/Class/MethodDecl.java index 0026c58..2a6373d 100644 --- a/src/main/java/abstractSyntaxTree/Class/MethodDecl.java +++ b/src/main/java/abstractSyntaxTree/Class/MethodDecl.java @@ -43,9 +43,12 @@ public class MethodDecl implements Node { TypeCheckResult result = new TypeCheckResult(); codeBlock.thisClass = classThatContainsMethod; - String CodeBlockType = codeBlock.typeCheck(methodContext, typeContext, localVars).type; - if(!Objects.equals(this.returnType, CodeBlockType)) - throw new TypeCheckException("Method returns " + CodeBlockType + ", but should return " + this.returnType + ". "); + String codeBlockType = codeBlock.typeCheck(methodContext, typeContext, localVars).type; + if(Objects.equals(this.name, classThatContainsMethod)) + codeBlockType = null; + + if(!Objects.equals(this.returnType, codeBlockType)) + throw new TypeCheckException("Method returns " + codeBlockType + ", but should return " + this.returnType + ". "); result.type = codeBlock.returnType; return result; }