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;
|
||||
|
||||
if (memberAccessNode.thisExpr) {
|
||||
currentType = new ReferenceType(currentClass.identifier);
|
||||
}
|
||||
|
||||
for (String s : memberAccessNode.identifiers) {
|
||||
if (currentType == null) {
|
||||
if (currentScope.getLocalVar(s) != null) {
|
||||
@ -552,7 +556,7 @@ public class SemanticAnalyzer implements SemanticVisitor {
|
||||
var currentTypeClass = context.getClass(reference.getIdentifier());
|
||||
|
||||
var currentField = currentTypeClass.getField(s);
|
||||
if (currentField.getAccessModifier().accessType == EnumAccessModifierNode.PUBLIC) {
|
||||
if (currentField.getAccessModifier().accessType == EnumAccessModifierNode.PUBLIC || memberAccessNode.thisExpr) {
|
||||
currentType = currentField.getType();
|
||||
} else {
|
||||
errors.add(new NotVisibleException("This field is not visible"));
|
||||
|
@ -4,13 +4,15 @@ import ast.members.FieldNode;
|
||||
import ast.type.*;
|
||||
import ast.type.type.*;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class FieldContext {
|
||||
|
||||
private AccessModifierNode accessModifier;
|
||||
private ITypeNode type;
|
||||
|
||||
public FieldContext(FieldNode field) {
|
||||
accessModifier = field.accessTypeNode;
|
||||
accessModifier = Objects.requireNonNullElseGet(field.accessTypeNode, () -> new AccessModifierNode("private"));
|
||||
type = field.type;
|
||||
}
|
||||
|
||||
|
@ -1,63 +1,9 @@
|
||||
|
||||
public class AllFeaturesClassExample {
|
||||
int a;
|
||||
boolean b;
|
||||
char c;
|
||||
int x;
|
||||
|
||||
public void controlStructures(int adf, boolean bool) {
|
||||
if (a > (10 + 8)) {
|
||||
} 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;
|
||||
public boolean test(boolean x){
|
||||
return x;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user