[FIR-TEST] Add new testdata generated after changes in previous commit
This commit is contained in:
+13
@@ -0,0 +1,13 @@
|
||||
public class X {
|
||||
private val x : String? = null
|
||||
public val y: CharSequence?
|
||||
get() = x?.subSequence(0, 1)
|
||||
public fun fn(): Int {
|
||||
if (y != null)
|
||||
// With non-default getter smartcast is not possible
|
||||
return y.length
|
||||
else
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
class Delegate {
|
||||
operator fun getValue(thisRef: Any?, prop: KProperty<*>): String? {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
class Example {
|
||||
private val p: String? by Delegate()
|
||||
|
||||
public val r: String? = "xyz"
|
||||
|
||||
public fun foo(): String {
|
||||
// Smart cast is not possible if property is delegated
|
||||
return if (p != null) p else ""
|
||||
}
|
||||
|
||||
public fun bar(): String {
|
||||
// But is possible for non-delegated value property even if it's public
|
||||
return if (r != null) r else ""
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
public interface A {
|
||||
public val x: Any
|
||||
}
|
||||
|
||||
public class B(override public val x: Any) : A {
|
||||
fun foo(): Int {
|
||||
if (x is String) {
|
||||
return x.length
|
||||
} else {
|
||||
return 0
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
// NB: should work after KT-5907 / KT-4450 fix
|
||||
|
||||
val currentTimeMillis = 1234L
|
||||
|
||||
public class Foo(protected val maxParsingTimeInMillis: Long?) {
|
||||
|
||||
var parsingStartTimeStamp = 0L
|
||||
|
||||
protected fun checkForParsingTimeout(): Boolean {
|
||||
if (maxParsingTimeInMillis == null)
|
||||
return true
|
||||
if (currentTimeMillis - parsingStartTimeStamp > maxParsingTimeInMillis)
|
||||
return false
|
||||
return true
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
public open class A() {
|
||||
public open val foo: Int? = 1
|
||||
}
|
||||
|
||||
infix fun Int.bar(i: Int) = i
|
||||
|
||||
fun test() {
|
||||
val p = A()
|
||||
// For open value properties, smart casts should not work
|
||||
if (p.foo is Int) p.foo bar 11
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
// MODULE: m1
|
||||
// FILE: a.kt
|
||||
|
||||
package a
|
||||
|
||||
public class X {
|
||||
public val x : String? = null
|
||||
}
|
||||
|
||||
// MODULE: m2(m1)
|
||||
// FILE: b.kt
|
||||
|
||||
package b
|
||||
|
||||
import a.X
|
||||
|
||||
public fun X.gav(): Int {
|
||||
if (x != null)
|
||||
// Smart cast is not possible if definition is in another module
|
||||
return x.length
|
||||
else
|
||||
return 0
|
||||
}
|
||||
|
||||
// FILE: c.kt
|
||||
|
||||
package a
|
||||
|
||||
public fun X.gav(): Int {
|
||||
if (x != null)
|
||||
// Even if it's in the same package
|
||||
return x.length
|
||||
else
|
||||
return 0
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
public open class X {
|
||||
protected val x : String? = null
|
||||
public fun fn(): Int {
|
||||
if (x != null)
|
||||
// Smartcast is possible for protected value property in the same class
|
||||
return x.length
|
||||
else
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
public class Y: X() {
|
||||
public fun bar(): Int {
|
||||
// Smartcast is possible even in derived class
|
||||
return if (x != null) x.length else 0
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
public class X {
|
||||
public val x : String? = null
|
||||
public fun fn(): Int {
|
||||
if (x != null)
|
||||
// Smartcast is possible because it's value property with default getter
|
||||
// used in the same module
|
||||
return x.length
|
||||
else
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
public class X {
|
||||
public var x : String? = null
|
||||
private var y: String? = "abc"
|
||||
public fun fn(): Int {
|
||||
if (x != null)
|
||||
// Smartcast is not possible for variable properties
|
||||
return x.length
|
||||
else if (y != null)
|
||||
// Even if they are private
|
||||
return y.length
|
||||
else
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user