Compare commits

..

2 Commits

Author SHA1 Message Date
Krauß, Josefine
f6bb836ee0 Merge remote-tracking branch 'origin/master' 2024-06-28 18:33:34 +02:00
Krauß, Josefine
7498ca6e4d constructor return type 2024-06-28 18:33:21 +02:00
2 changed files with 8 additions and 6 deletions

View File

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

View File

@ -42,7 +42,6 @@ public class Program implements Node {
typeContext.put(oneClass.name, classVars);
// build method context
HashMap<String, HashMap<String, ParameterList>> identifierAndMethod = new HashMap<>();
for (MethodDecl methodDecl : oneClass.methodDecls){
if(methodDecl.returnType == null) continue;
@ -60,8 +59,8 @@ public class Program implements Node {
if(oneClass.hasMain)
mainCounter++;
}
if(mainCounter != 1)
throw new TypeCheckException("There is not 1 Main method.");
// if(mainCounter != 1)
// throw new TypeCheckException("There is not 1 Main method.");
// typecheck each class
TypeCheckResult result = new TypeCheckResult();