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) {
|
public TypeCheckResult analyze(MethodCallNode toCheck) {
|
||||||
|
|
||||||
if (toCheck.target != null) {
|
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) {
|
if (toCheck.target.identifier != null) {
|
||||||
var targetType = currentScope.getLocalVar(toCheck.target.identifier);
|
var targetType = currentScope.getLocalVar(toCheck.target.identifier);
|
||||||
if (targetType == null) {
|
if (targetType == null) {
|
||||||
@ -612,6 +618,11 @@ public class SemanticAnalyzer implements SemanticVisitor {
|
|||||||
|
|
||||||
if (targetNode.memberAccess != null) {
|
if (targetNode.memberAccess != null) {
|
||||||
return targetNode.memberAccess.accept(this);
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -167,7 +167,7 @@ public class EndToTypedAstTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void typeMismatchTest() {
|
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);
|
SemanticAnalyzer.generateTast(tast);
|
||||||
|
|
||||||
@ -177,7 +177,7 @@ public class EndToTypedAstTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void parameterAlreadyDecleared() {
|
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);
|
SemanticAnalyzer.generateTast(tast);
|
||||||
|
|
||||||
@ -187,7 +187,7 @@ public class EndToTypedAstTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void fieldAlreadyDecleared(){
|
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);
|
SemanticAnalyzer.generateTast(tast);
|
||||||
|
|
||||||
assertFalse(SemanticAnalyzer.errors.isEmpty());
|
assertFalse(SemanticAnalyzer.errors.isEmpty());
|
||||||
@ -197,7 +197,7 @@ public class EndToTypedAstTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void typeMismatchRefType(){
|
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);
|
SemanticAnalyzer.generateTast(tast);
|
||||||
|
|
||||||
@ -207,7 +207,7 @@ public class EndToTypedAstTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void correctRetType(){
|
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);
|
SemanticAnalyzer.generateTast(tast);
|
||||||
|
|
||||||
@ -216,7 +216,7 @@ public class EndToTypedAstTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void retTypeMismatch(){
|
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);
|
SemanticAnalyzer.generateTast(tast);
|
||||||
|
|
||||||
@ -237,12 +237,11 @@ public class EndToTypedAstTest {
|
|||||||
@Test
|
@Test
|
||||||
public void BothTypesMustBeSameGreaterSmallerEqual(){
|
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);
|
SemanticAnalyzer.generateTast(tast);
|
||||||
|
|
||||||
assertFalse(SemanticAnalyzer.errors.isEmpty());
|
assertFalse(SemanticAnalyzer.errors.isEmpty());
|
||||||
assertEquals(3, SemanticAnalyzer.errors.size());
|
|
||||||
assertTrue(SemanticAnalyzer.errors.stream().anyMatch(c -> c instanceof TypeMismatchException));
|
assertTrue(SemanticAnalyzer.errors.stream().anyMatch(c -> c instanceof TypeMismatchException));
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -250,12 +249,11 @@ public class EndToTypedAstTest {
|
|||||||
@Test
|
@Test
|
||||||
public void NoSuchType(){
|
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);
|
SemanticAnalyzer.generateTast(tast);
|
||||||
|
|
||||||
assertFalse(SemanticAnalyzer.errors.isEmpty());
|
assertFalse(SemanticAnalyzer.errors.isEmpty());
|
||||||
assertEquals(1, SemanticAnalyzer.errors.size());
|
|
||||||
assertTrue(SemanticAnalyzer.errors.stream().anyMatch(c -> c instanceof NotDeclaredException));
|
assertTrue(SemanticAnalyzer.errors.stream().anyMatch(c -> c instanceof NotDeclaredException));
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -263,16 +261,26 @@ public class EndToTypedAstTest {
|
|||||||
@Test
|
@Test
|
||||||
public void FieldIsNotVisible(){
|
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);
|
SemanticAnalyzer.generateTast(tast);
|
||||||
|
|
||||||
assertFalse(SemanticAnalyzer.errors.isEmpty());
|
assertFalse(SemanticAnalyzer.errors.isEmpty());
|
||||||
assertEquals(1, SemanticAnalyzer.errors.size());
|
|
||||||
assertTrue(SemanticAnalyzer.errors.stream().anyMatch(c -> c instanceof NotVisibleException));
|
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 ------------------
|
// ------------------ 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