[FIR-TEST] Add new testdata generated after changes in previous commit

This commit is contained in:
Dmitriy Novozhilov
2019-12-11 16:16:22 +03:00
parent e9c02a1cca
commit 2536fa0cd5
4578 changed files with 104067 additions and 1 deletions
@@ -0,0 +1,23 @@
class My {
val y: Int
get() {
var x: Int?
x = 3
return x.hashCode()
}
fun test() {
var x: Int?
x = 2
x.hashCode()
fun bb() {
var x: Any?
x = 4
x.hashCode()
}
x = 4
// Really smart cast is possible but name shadowing by bb() prevents it
x.hashCode()
}
}
@@ -0,0 +1,10 @@
fun foo() {
var v: Any = 42
v.<!UNRESOLVED_REFERENCE!>length<!>()
v = "abc"
v.length
v = 42
v.<!UNRESOLVED_REFERENCE!>length<!>()
v = "abc"
v.length
}
@@ -0,0 +1,35 @@
fun foo(x: String) = x
fun test1() {
var c: Any? = "XXX"
if (c !is String) return
val newC: String? = "YYY"
if (newC != null) {
c = newC
}
<!INAPPLICABLE_CANDIDATE!>foo<!>(c)
}
fun test2() {
var c: Any? = "XXX"
if (c !is String) return
val newC: String? = "YYY"
if (newC is String) {
c = newC
}
<!INAPPLICABLE_CANDIDATE!>foo<!>(c)
}
fun test3() {
var c: Any? = "XXX"
if (c !is String) return
val newC: String? = "YYY"
if (newC == null) return
c = newC
<!INAPPLICABLE_CANDIDATE!>foo<!>(c)
}
@@ -0,0 +1,12 @@
fun x(): Boolean { return true }
public fun foo(pp: Any): Int {
var p = pp
do {
(p as String).length
if (p == "abc") break
p = 42
} while (!x())
// Smart cast is NOT possible here
return p.<!UNRESOLVED_REFERENCE!>length<!>()
}
@@ -0,0 +1,15 @@
public fun foo(xx: Any): Int {
var x = xx
do {
var y: Any
// After the check, smart cast should work
if (x is String) {
y = "xyz"
} else {
y = "abc"
}
// y!! in both branches
y.length
} while (!(x is String))
return x.<!UNRESOLVED_REFERENCE!>length<!>
}
@@ -0,0 +1,16 @@
public fun foo(xx: Any): Int {
var x = xx
do {
var y: Any
// After the check, smart cast should work
if (x is String) {
break
} else {
y = "abc"
}
// y!! in both branches
y.length
} while (true)
// We could have smart cast here but with break it's hard to detect
return x.<!UNRESOLVED_REFERENCE!>length<!>()
}
@@ -0,0 +1,73 @@
// !WITH_NEW_INFERENCE
// See KT-13468, KT-13765
fun basic(): String {
var current: String? = null
current = if (current == null) "bar" else current
return current
}
fun foo(flag: Boolean) {
var x: String? = null
if (x == null) {
x = if (flag) "34" else "12"
}
x.hashCode()
}
fun bar(flag: Boolean) {
var x: String? = null
if (x == null) {
x = when {
flag -> "34"
else -> "12"
}
}
x.hashCode()
}
fun baz(flag: Boolean) {
var x: String? = null
if (x == null) {
x = if (flag) {
"34"
} else {
"12"
}
}
x.hashCode()
}
fun gav(flag: Boolean, arg: String?) {
var x: String? = null
if (x == null) {
x = arg ?: if (flag) {
"34"
} else {
"12"
}
}
x.hashCode()
}
fun gau(flag: Boolean, arg: String?) {
var x: String? = null
if (x == null) {
x = if (flag) {
arg ?: "34"
} else {
arg ?: "12"
}
}
x.hashCode()
}
@@ -0,0 +1,9 @@
public fun bar(s: String) {
System.out.println("Length of $s is ${s.length}")
}
public fun foo() {
var s: Any = "not null"
if (s is String)
bar(s)
}
@@ -0,0 +1,13 @@
// See KT-5737
fun get(): Any {
return "abc"
}
fun foo(): Int {
var ss: Any = get()
return if (ss is String && ss.length > 0)
1
else
0
}
@@ -0,0 +1,11 @@
public fun bar(s: String) {
System.out.println("Length of $s is ${s.length}")
}
public fun foo() {
var s: Any = "not null"
if (s is String) {
s = 42
bar(s)
}
}
@@ -0,0 +1,18 @@
// FILE: My.java
public interface My {
String foo(String arg);
}
// FILE: test.kt
class Your {
val x = My() {
arg: String? ->
var y = arg
val z: String
if (y != null) z = y
else z = "42"
z
}
}
@@ -0,0 +1,11 @@
// See KT-774
fun box() : Int {
var a : Any = 1
var d = 1
if (a is Int) {
return a + d
} else {
return 2
}
}
@@ -0,0 +1,8 @@
fun foo() {
var v: Any = "xyz"
// It is possible in principle to provide smart cast here
// but now we decide that v is Any
v.<!UNRESOLVED_REFERENCE!>length<!>()
v = 42
v.<!UNRESOLVED_REFERENCE!>length<!>()
}
@@ -0,0 +1,23 @@
interface A {
fun ok(): Boolean
}
class B: A {
override fun ok(): Boolean { return true }
}
class C: A {
override fun ok(): Boolean { return false }
}
fun foo(): Boolean {
var v: A
v = B()
// No smart cast needed, but not a problem if ever
if (v.ok()) {
v = C()
}
// No smart cast needed, and no smart cast possible!
// We cannot choose between B and C
return v.ok()
}
@@ -0,0 +1,10 @@
// !WITH_NEW_INFERENCE
// !DIAGNOSTICS: -UNUSED_PARAMETER
fun foo(x: Int, f: () -> Unit, y: Int) {}
fun bar() {
var x: Int?
x = 4
foo(x, { x = null; x.<!UNRESOLVED_REFERENCE!>hashCode<!>() }, x)
}
@@ -0,0 +1,11 @@
// !WITH_NEW_INFERENCE
class MyClass(var p: String?)
fun bar(s: String): Int {
return s.length
}
fun foo(m: MyClass): Int {
m.p = "xyz"
return bar(m.p)
}
@@ -0,0 +1,10 @@
class MyClass(var p: String?)
fun bar(s: String?): Int {
return s?.length ?: -1
}
fun foo(m: MyClass): Int {
m.p = "xyz"
return bar(m.p)
}
@@ -0,0 +1,10 @@
class MyClass(var p: Any)
fun bar(s: Any): Int {
return s.hashCode()
}
fun foo(m: MyClass): Int {
m.p = "xyz"
return bar(m.p)
}
@@ -0,0 +1,10 @@
fun bar(s: Any): Int {
return s.hashCode()
}
class MyClass(var p: Any) {
fun foo(): Int {
p = "xyz"
return bar(p)
}
}
@@ -0,0 +1,13 @@
fun bar(s: Any): Int {
return s.hashCode()
}
class MyClass(var p: Any) {
fun foo(): Int {
p = "xyz"
if (p is String) {
return bar(p)
}
return -1
}
}
@@ -0,0 +1,9 @@
fun get(): Any {
return ""
}
fun foo(): Int {
var c: Any = get()
(c as String).length
return c.length // Previous line should make as unnecessary here.
}
@@ -0,0 +1,9 @@
public fun foo() {
var i: Any = 1
if (i is Int) {
while (i != 10) {
i++ // Here smart cast should not be performed due to a successor
i = ""
}
}
}
@@ -0,0 +1,8 @@
public fun foo() {
var i: Any = 1
if (i is Int) {
while (i != 10) {
i++
}
}
}
@@ -0,0 +1,13 @@
fun x(): Boolean { return true }
public fun foo(pp: Any): Int {
var p = pp
while(true) {
(p as String).length
if (x()) break
p = 42
}
// Smart cast is NOT possible here
// (we could provide it but p = 42 makes it difficult to understand)
return p.<!UNRESOLVED_REFERENCE!>length<!>()
}
@@ -0,0 +1,17 @@
fun String.next(): String {
return "abc"
}
fun list(start: String) {
var e: Any? = start
if (e==null) return
while (e is String) {
// Smart cast due to the loop condition
if (e.length == 0)
break
// We still have smart cast here despite of a break
e = e.next()
}
// e can never be null but we do not know it
e.hashCode()
}