missing case in methodcall

This commit is contained in:
Krauß, Josefine 2024-06-30 13:39:20 +02:00
parent 4bc38c0ff9
commit dd2842138f

View File

@ -35,7 +35,7 @@ public class MethodCallStatementExpression extends AbstractType implements IExpr
String classToSearchMethodIn = thisClass;
//method is called on something that is not this ???
if(this.receiver != null) {
if (this.receiver != null) {
if (!receiver.thisExpression) {
classToSearchMethodIn = localVars.get(receiver.identifier);
if (classToSearchMethodIn == null)
@ -46,7 +46,7 @@ public class MethodCallStatementExpression extends AbstractType implements IExpr
String currentType = "";
// receiver is instvar
if(receiver != null) {
if (receiver != null) {
if (receiver.instVarExpression != null) {
String Subreceiver = receiver.instVarExpression.receivers.get(0).identifier; // e
String mostLeftField = receiver.instVarExpression.fieldName; // example1
@ -56,17 +56,19 @@ public class MethodCallStatementExpression extends AbstractType implements IExpr
receiver.instVarExpression.thisClass = typeOfSubreceiver;
receiver.instVarExpression.typeCheck(methodContext, typeContext, localVars);
currentType = typeContext.get(typeOfSubreceiver).get(mostLeftField);
} else {
currentType = thisClass;
}
}else{
} else {
currentType = thisClass;
}
//if classToSearchMethodIn does not conatin method, throw exception. go through list and check each
for(int i = 0; i < receivingMethods.size(); i++){
for (int i = 0; i < receivingMethods.size(); i++) {
currentType = (String) methodContext.get(currentType).get(receivingMethods.get(i).methodName).keySet().toArray()[0];
if(currentType == null)
throw new TypeCheckException("The method " + methodName + " was not found in "+ classToSearchMethodIn + ".");
if (currentType == null)
throw new TypeCheckException("The method " + methodName + " was not found in " + classToSearchMethodIn + ".");
receivingMethods.get(i).thisClass = this.thisClass;
receivingMethods.get(i).checkParameters(methodContext, typeContext, localVars);
}
@ -175,7 +177,7 @@ public class MethodCallStatementExpression extends AbstractType implements IExpr
if (o == null || getClass() != o.getClass()) return false;
MethodCallStatementExpression methodCallStatementExpression = (MethodCallStatementExpression) o;
return (Objects.equals(methodName, methodCallStatementExpression.methodName)
&& Objects.equals(arguments, methodCallStatementExpression.arguments)
&& Objects.equals(arguments, methodCallStatementExpression.arguments)
);
}