Skip to content

Commit bbdc14a

Browse files
jesyspaclaude
andcommitted
Merge nullability tests into existing nullability.kt
Move tests from nullability_operations.kt into the existing verification/nullability.kt file. Use file-level ALWAYS_VALIDATE instead of per-function @AlwaysVerify to match the existing convention. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent d178441 commit bbdc14a

File tree

5 files changed

+146
-164
lines changed

5 files changed

+146
-164
lines changed

formver.compiler-plugin/test-gen/org/jetbrains/kotlin/formver/plugin/runners/FirLightTreeFormVerPluginDiagnosticsTestGenerated.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -494,12 +494,6 @@ public void testNullability() {
494494
runTest("formver.compiler-plugin/testData/diagnostics/verification/nullability.kt");
495495
}
496496

497-
@Test
498-
@TestMetadata("nullability_operations.kt")
499-
public void testNullability_operations() {
500-
runTest("formver.compiler-plugin/testData/diagnostics/verification/nullability_operations.kt");
501-
}
502-
503497
@Test
504498
@TestMetadata("stdlib_replacement_tests.kt")
505499
public void testStdlib_replacement_tests() {
Lines changed: 91 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,98 @@
1-
/nullability.kt:(24,35): info: Generated Viper text for return_null:
1+
/nullability.kt:(83,94): info: Generated Viper text for return_null:
22
method f$return_null$TF$() returns (ret$0: Ref)
33
ensures df$rt$isSubtype(df$rt$typeOf(ret$0), df$rt$nullable(df$rt$intType()))
44
{
55
ret$0 := df$rt$nullValue()
66
goto lbl$ret$0
77
label lbl$ret$0
88
}
9+
10+
/nullability.kt:(115,133): info: Generated Viper text for elvisDefaultOnNull:
11+
method f$elvisDefaultOnNull$TF$() returns (ret$0: Ref)
12+
ensures df$rt$isSubtype(df$rt$typeOf(ret$0), df$rt$intType())
13+
ensures df$rt$intFromRef(ret$0) == 42
14+
{
15+
var l0$x: Ref
16+
l0$x := df$rt$nullValue()
17+
if (l0$x != df$rt$nullValue()) {
18+
ret$0 := l0$x
19+
} else {
20+
ret$0 := df$rt$intToRef(42)}
21+
goto lbl$ret$0
22+
label lbl$ret$0
23+
}
24+
25+
/nullability.kt:(241,260): info: Generated Viper text for nullablePassthrough:
26+
method f$nullablePassthrough$TF$NT$Int(p$x: Ref) returns (ret$0: Ref)
27+
ensures df$rt$isSubtype(df$rt$typeOf(ret$0), df$rt$nullable(df$rt$intType()))
28+
ensures ret$0 == p$x
29+
{
30+
inhale df$rt$isSubtype(df$rt$typeOf(p$x), df$rt$nullable(df$rt$intType()))
31+
ret$0 := p$x
32+
goto lbl$ret$0
33+
label lbl$ret$0
34+
}
35+
36+
/nullability.kt:(347,364): info: Generated Viper text for returnNullLiteral:
37+
method f$returnNullLiteral$TF$() returns (ret$0: Ref)
38+
ensures df$rt$isSubtype(df$rt$typeOf(ret$0), df$rt$nullable(df$rt$intType()))
39+
ensures ret$0 == df$rt$nullValue()
40+
{
41+
ret$0 := df$rt$nullValue()
42+
goto lbl$ret$0
43+
label lbl$ret$0
44+
}
45+
46+
/nullability.kt:(450,475): info: Generated Viper text for nullComparisonReturnsTrue:
47+
method f$nullComparisonReturnsTrue$TF$() returns (ret$0: Ref)
48+
ensures df$rt$isSubtype(df$rt$typeOf(ret$0), df$rt$boolType())
49+
ensures df$rt$boolFromRef(ret$0) == true
50+
{
51+
var l0$x: Ref
52+
l0$x := df$rt$nullValue()
53+
ret$0 := df$rt$boolToRef(l0$x == df$rt$nullValue())
54+
goto lbl$ret$0
55+
label lbl$ret$0
56+
}
57+
58+
/nullability.kt:(595,624): info: Generated Viper text for nonNullComparisonReturnsFalse:
59+
method f$nonNullComparisonReturnsFalse$TF$() returns (ret$0: Ref)
60+
ensures df$rt$isSubtype(df$rt$typeOf(ret$0), df$rt$boolType())
61+
ensures df$rt$boolFromRef(ret$0) == false
62+
{
63+
var l0$x: Ref
64+
l0$x := df$rt$nullValue()
65+
ret$0 := sp$notBool(df$rt$boolToRef(l0$x == df$rt$nullValue()))
66+
goto lbl$ret$0
67+
label lbl$ret$0
68+
}
69+
70+
/nullability.kt:(745,761): info: Generated Viper text for elvisWithNonNull:
71+
method f$elvisWithNonNull$TF$T$Int(p$x: Ref) returns (ret$0: Ref)
72+
ensures df$rt$isSubtype(df$rt$typeOf(ret$0), df$rt$intType())
73+
ensures df$rt$intFromRef(ret$0) == df$rt$intFromRef(p$x)
74+
{
75+
var l0$y: Ref
76+
inhale df$rt$isSubtype(df$rt$typeOf(p$x), df$rt$intType())
77+
l0$y := p$x
78+
if (l0$y != df$rt$nullValue()) {
79+
ret$0 := l0$y
80+
} else {
81+
ret$0 := df$rt$intToRef(0)}
82+
goto lbl$ret$0
83+
label lbl$ret$0
84+
}
85+
86+
/nullability.kt:(870,887): info: Generated Viper text for smartcastInBranch:
87+
method f$smartcastInBranch$TF$NT$Int(p$n: Ref) returns (ret$0: Ref)
88+
ensures df$rt$isSubtype(df$rt$typeOf(ret$0), df$rt$intType())
89+
{
90+
inhale df$rt$isSubtype(df$rt$typeOf(p$n), df$rt$nullable(df$rt$intType()))
91+
if (!(p$n == df$rt$nullValue())) {
92+
ret$0 := p$n
93+
goto lbl$ret$0
94+
}
95+
ret$0 := df$rt$intToRef(0)
96+
goto lbl$ret$0
97+
label lbl$ret$0
98+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,58 @@
11
// ALWAYS_VALIDATE
22

3+
import org.jetbrains.kotlin.formver.plugin.postconditions
4+
35
fun <!VIPER_TEXT!>return_null<!>(): Int? = null
6+
7+
fun <!VIPER_TEXT!>elvisDefaultOnNull<!>(): Int {
8+
postconditions<Int> {
9+
it == 42
10+
}
11+
val x: Int? = null
12+
return x ?: 42
13+
}
14+
15+
fun <!VIPER_TEXT!>nullablePassthrough<!>(x: Int?): Int? {
16+
postconditions<Int?> {
17+
it == x
18+
}
19+
return x
20+
}
21+
22+
fun <!VIPER_TEXT!>returnNullLiteral<!>(): Int? {
23+
postconditions<Int?> {
24+
it == null
25+
}
26+
return null
27+
}
28+
29+
fun <!VIPER_TEXT!>nullComparisonReturnsTrue<!>(): Boolean {
30+
postconditions<Boolean> {
31+
it == true
32+
}
33+
val x: Int? = null
34+
return x == null
35+
}
36+
37+
fun <!VIPER_TEXT!>nonNullComparisonReturnsFalse<!>(): Boolean {
38+
postconditions<Boolean> {
39+
it == false
40+
}
41+
val x: Int? = null
42+
return x != null
43+
}
44+
45+
fun <!VIPER_TEXT!>elvisWithNonNull<!>(x: Int): Int {
46+
postconditions<Int> {
47+
it == x
48+
}
49+
val y: Int? = x
50+
return y ?: 0
51+
}
52+
53+
fun <!VIPER_TEXT!>smartcastInBranch<!>(n: Int?): Int {
54+
if (n != null) {
55+
return n
56+
}
57+
return 0
58+
}

formver.compiler-plugin/testData/diagnostics/verification/nullability_operations.fir.diag.txt

Lines changed: 0 additions & 89 deletions
This file was deleted.

formver.compiler-plugin/testData/diagnostics/verification/nullability_operations.kt

Lines changed: 0 additions & 68 deletions
This file was deleted.

0 commit comments

Comments
 (0)