Skip to content

Commit 3d87d7d

Browse files
committed
Fix more test for var smartcasts
1 parent 8cce6d0 commit 3d87d7d

File tree

11 files changed

+126
-0
lines changed

11 files changed

+126
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// See KT-5737
2+
fun get(): String? {
3+
return "abc"
4+
}
5+
6+
fun foo(): Int {
7+
var ss:String? = get()
8+
9+
return if (ss != null && <!DEBUG_INFO_SMARTCAST!>ss<!>.length() > 0)
10+
1
11+
else
12+
0
13+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package
2+
3+
internal fun foo(): kotlin.Int
4+
internal fun get(): kotlin.String?
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// See KT-969
2+
fun f() {
3+
var s: String?
4+
s = "a"
5+
var s1 = "" // String – ?
6+
if (<!SENSELESS_COMPARISON!>s != null<!>) { // Redundant
7+
s1.length()
8+
// We can do smartcast here and below
9+
s1 = <!DEBUG_INFO_SMARTCAST!>s<!>.toString() // return String?
10+
s1.length()
11+
s1 = <!DEBUG_INFO_SMARTCAST!>s<!>
12+
s1.length()
13+
// It's just an assignment without smartcast
14+
val s2 = s
15+
// But smartcast can be done here
16+
<!DEBUG_INFO_SMARTCAST!>s2<!>.length()
17+
// And also here
18+
val s3 = <!DEBUG_INFO_SMARTCAST!>s<!>.toString()
19+
s3.length()
20+
}
21+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package
2+
3+
internal fun f(): kotlin.Unit
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// See KT-774
2+
fun box() : Int {
3+
var a : Int? = 1
4+
var d = 1
5+
6+
if (a == null) {
7+
return 2
8+
} else {
9+
return <!DEBUG_INFO_SMARTCAST!>a<!> + d
10+
}
11+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package
2+
3+
internal fun box(): kotlin.Int
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
data class SomeObject(val n: SomeObject?) {
2+
fun doSomething() {}
3+
fun next(): SomeObject? = n
4+
}
5+
6+
7+
fun list(start: SomeObject) {
8+
var e: SomeObject? = start
9+
while (e != null) {
10+
<!DEBUG_INFO_SMARTCAST!>e<!>.doSomething()
11+
e = <!DEBUG_INFO_SMARTCAST!>e<!>.next()
12+
}
13+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package
2+
3+
internal fun list(/*0*/ start: SomeObject): kotlin.Unit
4+
5+
kotlin.data() internal final class SomeObject {
6+
public constructor SomeObject(/*0*/ n: SomeObject?)
7+
internal final val n: SomeObject?
8+
internal final /*synthesized*/ fun component1(): SomeObject?
9+
public final /*synthesized*/ fun copy(/*0*/ n: SomeObject? = ...): SomeObject
10+
internal final fun doSomething(): kotlin.Unit
11+
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
12+
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
13+
internal final fun next(): SomeObject?
14+
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
15+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
fun get(): String? {
2+
return ""
3+
}
4+
5+
fun foo(): Int {
6+
var c: String? = get()
7+
c!!.length()
8+
return <!DEBUG_INFO_SMARTCAST!>c<!>.length() // Previous line should make !! unnecessary here.
9+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package
2+
3+
internal fun foo(): kotlin.Int
4+
internal fun get(): kotlin.String?

compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11465,6 +11465,12 @@ public void testIfVarNotNull() throws Exception {
1146511465
doTest(fileName);
1146611466
}
1146711467

11468+
@TestMetadata("ifVarNotNullAnd.kt")
11469+
public void testIfVarNotNullAnd() throws Exception {
11470+
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/varnotnull/ifVarNotNullAnd.kt");
11471+
doTest(fileName);
11472+
}
11473+
1146811474
@TestMetadata("ifVarNullElse.kt")
1146911475
public void testIfVarNullElse() throws Exception {
1147011476
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/varnotnull/ifVarNullElse.kt");
@@ -11477,12 +11483,30 @@ public void testIfVarNullReturn() throws Exception {
1147711483
doTest(fileName);
1147811484
}
1147911485

11486+
@TestMetadata("inference.kt")
11487+
public void testInference() throws Exception {
11488+
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/varnotnull/inference.kt");
11489+
doTest(fileName);
11490+
}
11491+
11492+
@TestMetadata("infix.kt")
11493+
public void testInfix() throws Exception {
11494+
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/varnotnull/infix.kt");
11495+
doTest(fileName);
11496+
}
11497+
1148011498
@TestMetadata("initialization.kt")
1148111499
public void testInitialization() throws Exception {
1148211500
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/varnotnull/initialization.kt");
1148311501
doTest(fileName);
1148411502
}
1148511503

11504+
@TestMetadata("iterations.kt")
11505+
public void testIterations() throws Exception {
11506+
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/varnotnull/iterations.kt");
11507+
doTest(fileName);
11508+
}
11509+
1148611510
@TestMetadata("kt2865.kt")
1148711511
public void testKt2865() throws Exception {
1148811512
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/varnotnull/kt2865.kt");
@@ -11590,6 +11614,12 @@ public void testVarChangedInLoop() throws Exception {
1159011614
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/varnotnull/varChangedInLoop.kt");
1159111615
doTest(fileName);
1159211616
}
11617+
11618+
@TestMetadata("varCheck.kt")
11619+
public void testVarCheck() throws Exception {
11620+
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/varnotnull/varCheck.kt");
11621+
doTest(fileName);
11622+
}
1159311623
}
1159411624
}
1159511625

0 commit comments

Comments
 (0)