Compare commits
2 Commits
4b7cb0b150
...
f6bb836ee0
Author | SHA1 | Date | |
---|---|---|---|
|
f6bb836ee0 | ||
|
7498ca6e4d |
@ -43,9 +43,12 @@ public class MethodDecl implements Node {
|
|||||||
|
|
||||||
TypeCheckResult result = new TypeCheckResult();
|
TypeCheckResult result = new TypeCheckResult();
|
||||||
codeBlock.thisClass = classThatContainsMethod;
|
codeBlock.thisClass = classThatContainsMethod;
|
||||||
String CodeBlockType = codeBlock.typeCheck(methodContext, typeContext, localVars).type;
|
String codeBlockType = codeBlock.typeCheck(methodContext, typeContext, localVars).type;
|
||||||
if(!Objects.equals(this.returnType, CodeBlockType))
|
if(Objects.equals(this.name, classThatContainsMethod))
|
||||||
throw new TypeCheckException("Method returns " + CodeBlockType + ", but should return " + this.returnType + ". ");
|
codeBlockType = null;
|
||||||
|
|
||||||
|
if(!Objects.equals(this.returnType, codeBlockType))
|
||||||
|
throw new TypeCheckException("Method returns " + codeBlockType + ", but should return " + this.returnType + ". ");
|
||||||
result.type = codeBlock.returnType;
|
result.type = codeBlock.returnType;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,6 @@ public class Program implements Node {
|
|||||||
typeContext.put(oneClass.name, classVars);
|
typeContext.put(oneClass.name, classVars);
|
||||||
|
|
||||||
// build method context
|
// build method context
|
||||||
|
|
||||||
HashMap<String, HashMap<String, ParameterList>> identifierAndMethod = new HashMap<>();
|
HashMap<String, HashMap<String, ParameterList>> identifierAndMethod = new HashMap<>();
|
||||||
for (MethodDecl methodDecl : oneClass.methodDecls){
|
for (MethodDecl methodDecl : oneClass.methodDecls){
|
||||||
if(methodDecl.returnType == null) continue;
|
if(methodDecl.returnType == null) continue;
|
||||||
@ -60,8 +59,8 @@ public class Program implements Node {
|
|||||||
if(oneClass.hasMain)
|
if(oneClass.hasMain)
|
||||||
mainCounter++;
|
mainCounter++;
|
||||||
}
|
}
|
||||||
if(mainCounter != 1)
|
// if(mainCounter != 1)
|
||||||
throw new TypeCheckException("There is not 1 Main method.");
|
// throw new TypeCheckException("There is not 1 Main method.");
|
||||||
|
|
||||||
// typecheck each class
|
// typecheck each class
|
||||||
TypeCheckResult result = new TypeCheckResult();
|
TypeCheckResult result = new TypeCheckResult();
|
||||||
|
Loading…
Reference in New Issue
Block a user