Skip to content

Commit fbc056e

Browse files
Add regression tests for var locals and yielded refined constructors (#344, #346, #347)
These reproducers already verify on main: since Spoon parses at the project's compliance level (21 by default, #352, #368), a var local gets the static type of its initialiser instead of a type named "var", and switch expressions with yield are modelled correctly. With a pre-10 compliance level, the null type of a var comparison is now also handled as an unresolved type (#388). Fixes #344 Fixes #346 Fixes #347 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent d079005 commit fbc056e

4 files changed

Lines changed: 87 additions & 0 deletions

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package testSuite;
2+
3+
import liquidjava.specification.Refinement;
4+
import liquidjava.specification.RefinementAlias;
5+
6+
// A var local has the static type of its initialiser (#344, #347)
7+
@SuppressWarnings("unused")
8+
@RefinementAlias("Port(int x) { 0 <= x && x <= 65535 }")
9+
public class CorrectVarLocal {
10+
static String name() {
11+
return "x";
12+
}
13+
14+
static void connect(@Refinement("Port(_)") int port) {
15+
}
16+
17+
static void nullCheck() {
18+
var n = name();
19+
if (n == null) {
20+
throw new IllegalArgumentException("no name");
21+
}
22+
}
23+
24+
static void refinedArgument() {
25+
var port = 80;
26+
connect(port);
27+
}
28+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package testSuite;
2+
3+
import liquidjava.specification.Refinement;
4+
5+
// Yielding a call to a refined constructor from a switch expression (#346)
6+
@SuppressWarnings("unused")
7+
public class CorrectYieldRefinedConstructor {
8+
static class Conn {
9+
public Conn(@Refinement("_ > 0") int port) {
10+
}
11+
}
12+
13+
static Conn open(String scheme) {
14+
return switch (scheme) {
15+
case "tcp" -> {
16+
yield new Conn(80);
17+
}
18+
default -> new Conn(1);
19+
};
20+
}
21+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package testSuite;
2+
3+
import liquidjava.specification.Refinement;
4+
import liquidjava.specification.RefinementAlias;
5+
6+
// The value of a var local is still checked against a refined parameter (#347)
7+
@SuppressWarnings("unused")
8+
@RefinementAlias("Port(int x) { 0 <= x && x <= 65535 }")
9+
public class ErrorVarLocal {
10+
static void connect(@Refinement("Port(_)") int port) {
11+
}
12+
13+
static void refinedArgument() {
14+
var port = 70000;
15+
connect(port); // Expect: Refinement Error
16+
}
17+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package testSuite;
2+
3+
import liquidjava.specification.Refinement;
4+
5+
// The arguments of a refined constructor yielded from a switch expression are checked (#346)
6+
@SuppressWarnings("unused")
7+
public class ErrorYieldRefinedConstructor {
8+
static class Conn {
9+
public Conn(@Refinement("_ > 0") int port) {
10+
}
11+
}
12+
13+
static Conn open(String scheme) {
14+
return switch (scheme) {
15+
case "tcp" -> {
16+
yield new Conn(-1); // Expect: Refinement Error
17+
}
18+
default -> new Conn(1);
19+
};
20+
}
21+
}

0 commit comments

Comments
 (0)