instvar special case
This commit is contained in:
parent
3dcaad62f9
commit
94b3830561
@ -5,6 +5,7 @@ class TestClass {
|
|||||||
public TestClass(){i = 3456;}
|
public TestClass(){i = 3456;}
|
||||||
int meth(int n){
|
int meth(int n){
|
||||||
Example e = new Example();
|
Example e = new Example();
|
||||||
|
e.example1 = new TestClass();
|
||||||
int abc = e.example1.m1(2).m2().m3();
|
int abc = e.example1.m1(2).m2().m3();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -8,17 +8,18 @@ public class TypeCheckHelper {
|
|||||||
boolean type1Primitiv = Objects.equals(type1, "boolean") || Objects.equals(type1, "int") || Objects.equals(type1, "char");
|
boolean type1Primitiv = Objects.equals(type1, "boolean") || Objects.equals(type1, "int") || Objects.equals(type1, "char");
|
||||||
boolean type2Primitiv = Objects.equals(type2, "boolean") || Objects.equals(type2, "int") || Objects.equals(type2, "char");
|
boolean type2Primitiv = Objects.equals(type2, "boolean") || Objects.equals(type2, "int") || Objects.equals(type2, "char");
|
||||||
|
|
||||||
String result;
|
String result = "class";
|
||||||
if(type1Primitiv && type2Primitiv){
|
if(type1Primitiv && type2Primitiv){
|
||||||
if(Objects.equals(type1, type2)){
|
if(Objects.equals(type1, type2)){
|
||||||
result = type1;
|
result = type1;
|
||||||
}else{
|
}else{
|
||||||
throw new TypeCheckException("There is no upper bound between " + type1 + " and " + type2 + ".");
|
throw new TypeCheckException("There is no upper bound between " + type1 + " and " + type2 + ".");
|
||||||
}
|
}
|
||||||
}else if(type1Primitiv || type2Primitiv){
|
}else if(type1Primitiv ^ type2Primitiv){
|
||||||
throw new TypeCheckException("There is no upper bound between " + type1 + " and " + type2 + ".");
|
throw new TypeCheckException("There is no upper bound between " + type1 + " and " + type2 + ".");
|
||||||
}else{
|
}else{
|
||||||
result = "class";
|
if(Objects.equals(type1, type2))
|
||||||
|
result = type1;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -45,6 +45,8 @@ public class AssignStatementExpression extends AbstractType implements IExpressi
|
|||||||
leftType.type = typeContext.get(thisClass).get(identifier);
|
leftType.type = typeContext.get(thisClass).get(identifier);
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
|
if(left instanceof InstVarExpression instVarExpression)
|
||||||
|
instVarExpression.thisClass = this.thisClass;
|
||||||
leftType = left.typeCheck(methodContext, typeContext, localVars);
|
leftType = left.typeCheck(methodContext, typeContext, localVars);
|
||||||
}
|
}
|
||||||
TypeCheckResult rightType = right.typeCheck(methodContext, typeContext, localVars);
|
TypeCheckResult rightType = right.typeCheck(methodContext, typeContext, localVars);
|
||||||
|
Loading…
Reference in New Issue
Block a user