bugfix nullpointer if no receiver

This commit is contained in:
Krauß, Josefine 2024-06-26 16:12:21 +02:00
parent 77a6dae94f
commit ed2f64eff9
2 changed files with 19 additions and 18 deletions

View File

@ -1,11 +1,9 @@
class Example1 { class Example1 {
int i;
int a = 12345;
Example e; Example e;
public Example1(){i = 3456;} public Example1(){}
int meth(int n){ int meth(int n){
Example e = new Example(); Example e = new Example();
int abc = e.example1.m1(2).m2().m3(); int i = m1(2).m2().m3();
return 0; return 0;
} }
@ -15,9 +13,6 @@ class Example1 {
} }
class Example { class Example {
int i;
boolean b;
char c;
Example1 example1; Example1 example1;
Example1 m(int a){ Example1 m(int a){
return new Example1(); return new Example1();

View File

@ -35,16 +35,19 @@ public class MethodCallStatementExpression extends AbstractType implements IExpr
String classToSearchMethodIn = thisClass; String classToSearchMethodIn = thisClass;
//method is called on something that is not this ??? //method is called on something that is not this ???
if(!receiver.thisExpression){ if(this.receiver != null) {
if (!receiver.thisExpression) {
classToSearchMethodIn = localVars.get(receiver.identifier); classToSearchMethodIn = localVars.get(receiver.identifier);
if(classToSearchMethodIn == null) if (classToSearchMethodIn == null)
classToSearchMethodIn = thisClass; classToSearchMethodIn = thisClass;
} }
}
String currentType = ""; String currentType = "";
// receiver is instvar // receiver is instvar
if(receiver.instVarExpression != null){ if(receiver != null) {
if (receiver.instVarExpression != null) {
String Subreceiver = receiver.instVarExpression.receivers.get(0).identifier; // e String Subreceiver = receiver.instVarExpression.receivers.get(0).identifier; // e
String mostLeftField = receiver.instVarExpression.fieldName; // example1 String mostLeftField = receiver.instVarExpression.fieldName; // example1
@ -54,6 +57,9 @@ public class MethodCallStatementExpression extends AbstractType implements IExpr
receiver.instVarExpression.typeCheck(methodContext, typeContext, localVars); receiver.instVarExpression.typeCheck(methodContext, typeContext, localVars);
currentType = typeContext.get(typeOfSubreceiver).get(mostLeftField); currentType = typeContext.get(typeOfSubreceiver).get(mostLeftField);
} }
}else{
currentType = thisClass;
}
//if classToSearchMethodIn does not conatin method, throw exception. go through list and check each //if classToSearchMethodIn does not conatin method, throw exception. go through list and check each