Update the typeCheck of methods TypedFieldVarAccess

This commit is contained in:
ahmad 2024-05-11 13:52:55 +02:00
parent 5cad5992f2
commit 9e45c65ea3

View File

@ -28,38 +28,36 @@ public class TypedFieldVarAccess implements TypedExpression {
recursiveOwnerChain = getKindOfExpression(localVar, clas, unTypedFieldVarAccess.recursiveOwnerChain());
name = unTypedFieldVarAccess.id();
if(field) {
if (clas.isThereField(name)) {
type = clas.getFieldType(name);
}
} else if(localVar.containsKey(name)){
type = localVar.get(name);
}else{
throw new RuntimeException("Variable not declared");
}
}
@Override
public Type typeCheck(Map<String, Type> localVar, TypedClass clas) {
if(field){
if (clas.isThereField(name)) {
type = clas.getFieldType(name);
return clas.getFieldType(name);
}
}else{
if (clas.isThereField(name)) {
type = clas.getFieldType(name);
return clas.getFieldType(name);
}else if(clas.isCurrentConstructorPresent()){
if(clas.isParameterNameInCurrentConstructor(name)){
type = clas.getParameterTypeInCurrentConstructor(name);
return clas.getParameterTypeInCurrentConstructor(name);
}
}else if(clas.isCurrentMethodPresent()){
if(clas.isParameterWitNameInMethod(name)){
type = clas.getParameterType(name);
}else if(localVar.containsKey(name)){
type = clas.getParameterTypeInCurrentMethod(name);
return clas.getParameterTypeInCurrentMethod(name);
}
}
if(localVar.containsKey(name)) {
type = localVar.get(name);
return localVar.get(name);
}
}
return type;
throw new RuntimeException("Variable "+name+" not declared ");
}
@Override