Skip to content

Commit b760be9

Browse files
committed
Add Tests
1 parent 96ea969 commit b760be9

File tree

4 files changed

+43
-4
lines changed

4 files changed

+43
-4
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package testSuite;
2+
3+
import liquidjava.specification.Refinement;
4+
5+
public class CorrectChars {
6+
7+
@Refinement("_ == 65")
8+
int getA() {
9+
return 'A';
10+
}
11+
12+
void test() {
13+
printLetter('A');
14+
printLetter('Z');
15+
printLetter('a');
16+
printLetter('z');
17+
}
18+
19+
void printLetter(@Refinement("_ >= 65 && _ <= 90 || _ >= 97 && _ <= 122") char c) {
20+
System.out.println(c);
21+
}
22+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
package testSuite;
3+
4+
import liquidjava.specification.Refinement;
5+
6+
public class ErrorChars {
7+
8+
void test() {
9+
printLetter('$'); // error
10+
}
11+
12+
void printLetter(@Refinement("_ >= 65 && _ <= 90 || _ >= 97 && _ <= 122") char c) {
13+
System.out.println(c);
14+
}
15+
}

liquidjava-verifier/src/main/java/liquidjava/rj_language/ast/typing/TypeInfer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ else if (e instanceof LiteralLong)
3939
return Optional.of(Utils.getType("long", factory));
4040
else if (e instanceof LiteralReal)
4141
return Optional.of(Utils.getType("double", factory));
42-
else if (e instanceof LiteralBoolean)
43-
return boolType(factory);
4442
else if (e instanceof LiteralChar)
4543
return Optional.of(Utils.getType("char", factory));
44+
else if (e instanceof LiteralBoolean)
45+
return boolType(factory);
4646
else if (e instanceof Var)
4747
return varType(ctx, (Var) e);
4848
else if (e instanceof UnaryExpression)

liquidjava-verifier/src/main/java/liquidjava/smt/TranslatorContextToZ3.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ public static void storeVariablesSubtypes(Context z3, List<RefinedVariable> vari
4242
private static Expr<?> getExpr(Context z3, String name, CtTypeReference<?> type) {
4343
String typeName = type.getQualifiedName();
4444
return switch (typeName) {
45-
case "int", "short", "java.lang.Integer", "java.lang.Short" -> z3.mkIntConst(name);
45+
case "int", "short", "char", "java.lang.Integer", "java.lang.Short", "java.lang.Character" ->
46+
z3.mkIntConst(name);
4647
case "boolean", "java.lang.Boolean" -> z3.mkBoolConst(name);
4748
case "long", "java.lang.Long" -> z3.mkRealConst(name);
4849
case "float", "double", "java.lang.Float", "java.lang.Double" -> (FPExpr) z3.mkConst(name, z3.mkFPSort64());
@@ -81,7 +82,8 @@ private static void addBuiltinFunctions(Context z3, Map<String, FuncDecl<?>> fun
8182

8283
static Sort getSort(Context z3, String sort) {
8384
return switch (sort) {
84-
case "int", "short", "java.lang.Integer", "java.lang.Short" -> z3.getIntSort();
85+
case "int", "short", "char", "java.lang.Integer", "java.lang.Short", "java.lang.Character" ->
86+
z3.getIntSort();
8587
case "boolean", "java.lang.Boolean" -> z3.getBoolSort();
8688
case "long", "java.lang.Long" -> z3.getRealSort();
8789
case "float", "java.lang.Float" -> z3.mkFPSort32();

0 commit comments

Comments
 (0)