added private fields
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
7b1e6fced4
commit
f3e3158460
@ -24,6 +24,7 @@ import ast.statementexpressions.crementexpressions.IncrementNode;
|
||||
import ast.statementexpressions.methodcallstatementnexpressions.MethodCallNode;
|
||||
import ast.statementexpressions.methodcallstatementnexpressions.TargetNode;
|
||||
import ast.statements.*;
|
||||
import ast.type.AccessModifierNode;
|
||||
import ast.type.EnumAccessModifierNode;
|
||||
import ast.type.ValueNode;
|
||||
import ast.type.type.*;
|
||||
@ -411,8 +412,18 @@ public class SemanticAnalyzer implements SemanticVisitor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeCheckResult analyze(NonCalculationNode toCheck) {
|
||||
return null;
|
||||
public TypeCheckResult analyze(NonCalculationNode nonCalculationNode) {
|
||||
|
||||
var expResult = nonCalculationNode.expression.accept(this);
|
||||
var unaryResult = nonCalculationNode.unaryExpression.accept(this);
|
||||
|
||||
if(Objects.equals(expResult.getType(), unaryResult.getType())){
|
||||
return new TypeCheckResult(expResult.isValid() && unaryResult.isValid(), expResult.getType());
|
||||
} else {
|
||||
errors.add(new TypeMismatchException("NonCalculation node " + nonCalculationNode.getType() + " does not match expression " + expResult.getType()));
|
||||
}
|
||||
|
||||
return new TypeCheckResult(false, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -437,9 +448,12 @@ public class SemanticAnalyzer implements SemanticVisitor {
|
||||
} else if(unary.value != null){
|
||||
var result = unary.value.accept(this);
|
||||
return new TypeCheckResult(result.isValid(), result.getType());
|
||||
} else if(unary.memberAccess != null){
|
||||
var result = unary.memberAccess.accept(this);
|
||||
return new TypeCheckResult(result.isValid(), result.getType());
|
||||
}
|
||||
|
||||
return new TypeCheckResult(valid, null);
|
||||
return new TypeCheckResult(false, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -464,7 +478,11 @@ public class SemanticAnalyzer implements SemanticVisitor {
|
||||
var currentTypeClass = context.getClass(reference.getIdentifier());
|
||||
|
||||
var currentField = currentTypeClass.getField(s);
|
||||
currentType = currentField.getType();
|
||||
if(currentField.getAccessModifier().accessType == EnumAccessModifierNode.PUBLIC){
|
||||
currentType = currentField.getType();
|
||||
} else {
|
||||
errors.add(new NotVisibleException("This field is not visible"));
|
||||
return new TypeCheckResult(false, null); }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -18,4 +18,8 @@ public class FieldContext {
|
||||
return type;
|
||||
}
|
||||
|
||||
public AccessModifierNode getAccessModifier() {
|
||||
return accessModifier;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,20 @@
|
||||
// @expected: NotVisibleException
|
||||
public class Test{
|
||||
|
||||
public Car c;
|
||||
|
||||
public int test(){
|
||||
return c.speed;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class Car{
|
||||
|
||||
private int speed;
|
||||
|
||||
public int getSpeed(){
|
||||
return speed;
|
||||
}
|
||||
|
||||
}
|
@ -1,21 +1,26 @@
|
||||
public class Test{
|
||||
|
||||
public int i;
|
||||
public boolean b;
|
||||
public class Test {
|
||||
|
||||
public int test(){
|
||||
|
||||
return this.test(b);
|
||||
public Car c;
|
||||
|
||||
public int test(boolean b, int x) {
|
||||
if (b == true) {
|
||||
return c.getSpeed();
|
||||
} else {
|
||||
x++;
|
||||
return x;
|
||||
}
|
||||
}
|
||||
|
||||
public void test(int a){
|
||||
}
|
||||
|
||||
public class Car {
|
||||
|
||||
private int speed;
|
||||
|
||||
public int getSpeed() {
|
||||
return speed;
|
||||
}
|
||||
|
||||
public int test(boolean bool){
|
||||
int ret = 1;
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user