Skip to content

Commit b1d6701

Browse files
committed
Check If Refinements Are Boolean Expressions
1 parent d906b45 commit b1d6701

3 files changed

Lines changed: 32 additions & 2 deletions

File tree

liquidjava-verifier/pom.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,17 @@
9595
</execution>
9696
</executions>
9797
</plugin>
98+
<plugin>
99+
<groupId>org.apache.maven.plugins</groupId>
100+
<artifactId>maven-compiler-plugin</artifactId>
101+
<version>3.11.0</version>
102+
<configuration>
103+
<release>24</release>
104+
<compilerArgs>
105+
<arg>--enable-preview</arg>
106+
</compilerArgs>
107+
</configuration>
108+
</plugin>
98109
</plugins>
99110
</build>
100111

liquidjava-verifier/src/main/java/liquidjava/processor/refinement_checker/TypeChecker.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,15 @@ public Optional<Predicate> getRefinementFromAnnotation(CtElement element) throws
8888
}
8989
if (ref.isPresent()) {
9090
Predicate p = new Predicate(ref.get(), element, errorEmitter);
91+
92+
// check if refinement is valid
93+
if (!p.getExpression().isBooleanExpression()) {
94+
ErrorHandler.printCustomError(element, "Refinement predicate must be a boolean expression",
95+
errorEmitter);
96+
}
9197
if (errorEmitter.foundError())
9298
return Optional.empty();
99+
93100
constr = Optional.of(p);
94101
}
95102
return constr;

liquidjava-verifier/src/main/java/liquidjava/rj_language/ast/Expression.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
import java.util.List;
55
import java.util.Map;
66

7-
import com.microsoft.z3.Expr;
8-
97
import liquidjava.processor.context.Context;
108
import liquidjava.processor.facade.AliasDTO;
119
import liquidjava.rj_language.ast.typing.TypeInfer;
@@ -53,6 +51,20 @@ public boolean isLiteral() {
5351
return this instanceof LiteralInt || this instanceof LiteralReal || this instanceof LiteralBoolean;
5452
}
5553

54+
/**
55+
* Checks if this expression produces a boolean type based on its structure
56+
* @return true if it is a boolean expression, false otherwise
57+
*/
58+
public boolean isBooleanExpression() {
59+
return switch (this) {
60+
case LiteralBoolean _, Ite _, AliasInvocation _, FunctionInvocation _ -> true;
61+
case GroupExpression ge -> ge.getExpression().isBooleanExpression();
62+
case BinaryExpression be -> be.isBooleanOperation() || be.isLogicOperation();
63+
case UnaryExpression ue -> ue.getOp().equals("!");
64+
default -> false;
65+
};
66+
}
67+
5668
/**
5769
* Substitutes the expression first given expression by the second
5870
*

0 commit comments

Comments
 (0)