fix if field and parameter have same identifier
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
82356ec189
commit
2537051668
@ -535,6 +535,10 @@ public class SemanticAnalyzer implements SemanticVisitor {
|
|||||||
|
|
||||||
ITypeNode currentType = null;
|
ITypeNode currentType = null;
|
||||||
|
|
||||||
|
if (memberAccessNode.thisExpr) {
|
||||||
|
currentType = new ReferenceType(currentClass.identifier);
|
||||||
|
}
|
||||||
|
|
||||||
for (String s : memberAccessNode.identifiers) {
|
for (String s : memberAccessNode.identifiers) {
|
||||||
if (currentType == null) {
|
if (currentType == null) {
|
||||||
if (currentScope.getLocalVar(s) != null) {
|
if (currentScope.getLocalVar(s) != null) {
|
||||||
@ -552,7 +556,7 @@ public class SemanticAnalyzer implements SemanticVisitor {
|
|||||||
var currentTypeClass = context.getClass(reference.getIdentifier());
|
var currentTypeClass = context.getClass(reference.getIdentifier());
|
||||||
|
|
||||||
var currentField = currentTypeClass.getField(s);
|
var currentField = currentTypeClass.getField(s);
|
||||||
if (currentField.getAccessModifier().accessType == EnumAccessModifierNode.PUBLIC) {
|
if (currentField.getAccessModifier().accessType == EnumAccessModifierNode.PUBLIC || memberAccessNode.thisExpr) {
|
||||||
currentType = currentField.getType();
|
currentType = currentField.getType();
|
||||||
} else {
|
} else {
|
||||||
errors.add(new NotVisibleException("This field is not visible"));
|
errors.add(new NotVisibleException("This field is not visible"));
|
||||||
|
@ -4,13 +4,15 @@ import ast.members.FieldNode;
|
|||||||
import ast.type.*;
|
import ast.type.*;
|
||||||
import ast.type.type.*;
|
import ast.type.type.*;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
public class FieldContext {
|
public class FieldContext {
|
||||||
|
|
||||||
private AccessModifierNode accessModifier;
|
private AccessModifierNode accessModifier;
|
||||||
private ITypeNode type;
|
private ITypeNode type;
|
||||||
|
|
||||||
public FieldContext(FieldNode field) {
|
public FieldContext(FieldNode field) {
|
||||||
accessModifier = field.accessTypeNode;
|
accessModifier = Objects.requireNonNullElseGet(field.accessTypeNode, () -> new AccessModifierNode("private"));
|
||||||
type = field.type;
|
type = field.type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,63 +1,9 @@
|
|||||||
|
|
||||||
public class AllFeaturesClassExample {
|
public class AllFeaturesClassExample {
|
||||||
int a;
|
int x;
|
||||||
boolean b;
|
|
||||||
char c;
|
|
||||||
|
|
||||||
public void controlStructures(int adf, boolean bool) {
|
public boolean test(boolean x){
|
||||||
if (a > (10 + 8)) {
|
return x;
|
||||||
} else {
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
while (a > adf) {
|
|
||||||
a--;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < 5; i++) {
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// void logicalOperations() {
|
|
||||||
// // Logische UND-Operation
|
|
||||||
// if (b && a > 5) {
|
|
||||||
//// System.out.println("a ist größer als 5 und b ist wahr");
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// // Logische ODER-Operation
|
|
||||||
// if (b || a < 5) {
|
|
||||||
//// System.out.println("b ist wahr oder a ist kleiner als 5");
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// public static void main(String[] args) {
|
|
||||||
// AllFeaturesClassExample obj = new AllFeaturesClassExample(12, true, 'a');
|
|
||||||
// obj.controlStructures();
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class Test {
|
|
||||||
|
|
||||||
public Car c;
|
|
||||||
|
|
||||||
public int test(boolean b, int x) {
|
|
||||||
if (b == true) {
|
|
||||||
return c.getSpeed();
|
|
||||||
} else {
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public class Car {
|
|
||||||
|
|
||||||
private int speed;
|
|
||||||
|
|
||||||
public int getSpeed() {
|
|
||||||
return speed;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user