fixed MemberAccess in MethodCalls
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
This commit is contained in:
parent
97e0c228d6
commit
4bdb65a6ce
@ -325,6 +325,12 @@ public class SemanticAnalyzer implements SemanticVisitor {
|
||||
public TypeCheckResult analyze(MethodCallNode toCheck) {
|
||||
|
||||
if (toCheck.target != null) {
|
||||
if(toCheck.target.memberAccess == null){
|
||||
MemberAccessNode memberAccessNode = new MemberAccessNode(false);
|
||||
memberAccessNode.identifiers.add(currentClass.identifier);
|
||||
memberAccessNode.identifiers.add(toCheck.target.identifier);
|
||||
toCheck.target.memberAccess = memberAccessNode;
|
||||
}
|
||||
if (toCheck.target.identifier != null) {
|
||||
var targetType = currentScope.getLocalVar(toCheck.target.identifier);
|
||||
if (targetType == null) {
|
||||
@ -612,6 +618,11 @@ public class SemanticAnalyzer implements SemanticVisitor {
|
||||
|
||||
if (targetNode.memberAccess != null) {
|
||||
return targetNode.memberAccess.accept(this);
|
||||
} else if(targetNode.identifier != null) {
|
||||
MemberAccessNode memberAccessNode = new MemberAccessNode(false);
|
||||
memberAccessNode.identifiers.add(currentClass.identifier);
|
||||
memberAccessNode.identifiers.add(targetNode.identifier);
|
||||
targetNode.memberAccess = memberAccessNode;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -167,7 +167,7 @@ public class EndToTypedAstTest {
|
||||
|
||||
@Test
|
||||
public void typeMismatchTest() {
|
||||
ASTNode tast = SemanticHelper.generateTypedASTFrom("src/test/resources/input/johnsTests/TypeMismatchIntBool.java");
|
||||
ASTNode tast = SemanticHelper.generateTypedASTFrom("src/test/resources/input/singleFeatureSemanticTests/TypeMismatchIntBool.java");
|
||||
|
||||
SemanticAnalyzer.generateTast(tast);
|
||||
|
||||
@ -177,7 +177,7 @@ public class EndToTypedAstTest {
|
||||
|
||||
@Test
|
||||
public void parameterAlreadyDecleared() {
|
||||
ASTNode tast = SemanticHelper.generateTypedASTFrom("src/test/resources/input/johnsTests/ParameterAlreadyDecleared.java");
|
||||
ASTNode tast = SemanticHelper.generateTypedASTFrom("src/test/resources/input/singleFeatureSemanticTests/ParameterAlreadyDecleared.java");
|
||||
|
||||
SemanticAnalyzer.generateTast(tast);
|
||||
|
||||
@ -187,7 +187,7 @@ public class EndToTypedAstTest {
|
||||
|
||||
@Test
|
||||
public void fieldAlreadyDecleared(){
|
||||
ASTNode tast = SemanticHelper.generateTypedASTFrom("src/test/resources/input/johnsTests/FieldAlreadyDecleared.java");
|
||||
ASTNode tast = SemanticHelper.generateTypedASTFrom("src/test/resources/input/singleFeatureSemanticTests/FieldAlreadyDecleared.java");
|
||||
SemanticAnalyzer.generateTast(tast);
|
||||
|
||||
assertFalse(SemanticAnalyzer.errors.isEmpty());
|
||||
@ -197,7 +197,7 @@ public class EndToTypedAstTest {
|
||||
|
||||
@Test
|
||||
public void typeMismatchRefType(){
|
||||
ASTNode tast = SemanticHelper.generateTypedASTFrom("src/test/resources/input/johnsTests/TypeMismatchRefType.java");
|
||||
ASTNode tast = SemanticHelper.generateTypedASTFrom("src/test/resources/input/singleFeatureSemanticTests/TypeMismatchRefType.java");
|
||||
|
||||
SemanticAnalyzer.generateTast(tast);
|
||||
|
||||
@ -207,7 +207,7 @@ public class EndToTypedAstTest {
|
||||
|
||||
@Test
|
||||
public void correctRetType(){
|
||||
ASTNode tast = SemanticHelper.generateTypedASTFrom("src/test/resources/input/johnsTests/CorrectRetType.java");
|
||||
ASTNode tast = SemanticHelper.generateTypedASTFrom("src/test/resources/input/singleFeatureSemanticTests/CorrectRetType.java");
|
||||
|
||||
SemanticAnalyzer.generateTast(tast);
|
||||
|
||||
@ -216,7 +216,7 @@ public class EndToTypedAstTest {
|
||||
|
||||
@Test
|
||||
public void retTypeMismatch(){
|
||||
ASTNode tast = SemanticHelper.generateTypedASTFrom("src/test/resources/input/johnsTests/RetTypeMismatch.java");
|
||||
ASTNode tast = SemanticHelper.generateTypedASTFrom("src/test/resources/input/singleFeatureSemanticTests/RetTypeMismatch.java");
|
||||
|
||||
SemanticAnalyzer.generateTast(tast);
|
||||
|
||||
@ -237,12 +237,11 @@ public class EndToTypedAstTest {
|
||||
@Test
|
||||
public void BothTypesMustBeSameGreaterSmallerEqual(){
|
||||
|
||||
ASTNode tast = SemanticHelper.generateTypedASTFrom("src/test/resources/input/johnsTests/BothTypesMustBeSame.java");
|
||||
ASTNode tast = SemanticHelper.generateTypedASTFrom("src/test/resources/input/singleFeatureSemanticTests/BothTypesMustBeSame.java");
|
||||
|
||||
SemanticAnalyzer.generateTast(tast);
|
||||
|
||||
assertFalse(SemanticAnalyzer.errors.isEmpty());
|
||||
assertEquals(3, SemanticAnalyzer.errors.size());
|
||||
assertTrue(SemanticAnalyzer.errors.stream().anyMatch(c -> c instanceof TypeMismatchException));
|
||||
|
||||
}
|
||||
@ -250,12 +249,11 @@ public class EndToTypedAstTest {
|
||||
@Test
|
||||
public void NoSuchType(){
|
||||
|
||||
ASTNode tast = SemanticHelper.generateTypedASTFrom("src/test/resources/input/johnsTests/ClassNotDeclared.java");
|
||||
ASTNode tast = SemanticHelper.generateTypedASTFrom("src/test/resources/input/singleFeatureSemanticTests/ClassNotDeclared.java");
|
||||
|
||||
SemanticAnalyzer.generateTast(tast);
|
||||
|
||||
assertFalse(SemanticAnalyzer.errors.isEmpty());
|
||||
assertEquals(1, SemanticAnalyzer.errors.size());
|
||||
assertTrue(SemanticAnalyzer.errors.stream().anyMatch(c -> c instanceof NotDeclaredException));
|
||||
|
||||
}
|
||||
@ -263,16 +261,26 @@ public class EndToTypedAstTest {
|
||||
@Test
|
||||
public void FieldIsNotVisible(){
|
||||
|
||||
ASTNode tast = SemanticHelper.generateTypedASTFrom("src/test/resources/input/johnsTests/FieldIsNotVisible.java");
|
||||
ASTNode tast = SemanticHelper.generateTypedASTFrom("src/test/resources/input/singleFeatureSemanticTests/FieldIsNotVisible.java");
|
||||
|
||||
SemanticAnalyzer.generateTast(tast);
|
||||
|
||||
assertFalse(SemanticAnalyzer.errors.isEmpty());
|
||||
assertEquals(1, SemanticAnalyzer.errors.size());
|
||||
assertTrue(SemanticAnalyzer.errors.stream().anyMatch(c -> c instanceof NotVisibleException));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ChainedMethods(){
|
||||
|
||||
ASTNode tast = SemanticHelper.generateTypedASTFrom("src/test/resources/input/singleFeatureSemanticTests/ChainedMethods.java");
|
||||
|
||||
SemanticAnalyzer.generateTast(tast);
|
||||
|
||||
assertTrue(SemanticAnalyzer.errors.isEmpty());
|
||||
|
||||
}
|
||||
|
||||
// ------------------ Helpers ------------------
|
||||
|
||||
/**
|
||||
|
@ -0,0 +1,29 @@
|
||||
public class Test {
|
||||
|
||||
public House h;
|
||||
|
||||
public int test(House h){
|
||||
return h.getW().getSize();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public class House {
|
||||
|
||||
private Window w;
|
||||
|
||||
public Window getW(){
|
||||
return w;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class Window{
|
||||
|
||||
private int size;
|
||||
|
||||
public int getSize() {
|
||||
return size;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user