[FIR-TEST] Add new testdata generated after changes in previous commit
This commit is contained in:
+7
@@ -0,0 +1,7 @@
|
||||
package a
|
||||
|
||||
fun <T> foo(u: T, v: T): T = u
|
||||
|
||||
fun test(s: String?) {
|
||||
val r: String = foo(s!!, s)
|
||||
}
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// !CHECK_TYPE
|
||||
|
||||
package a
|
||||
|
||||
fun <T> id(t: T): T = t
|
||||
|
||||
fun <T> two(u: T, v: T): T = u
|
||||
|
||||
fun <T> three(a: T, b: T, c: T): T = c
|
||||
|
||||
interface A
|
||||
interface B: A
|
||||
interface C: A
|
||||
|
||||
fun test(a: A, b: B, c: C) {
|
||||
if (a is B && a is C) {
|
||||
val d: C = id(a)
|
||||
val e: Any = id(a)
|
||||
val f = id(a)
|
||||
checkSubtype<A>(f)
|
||||
val g = two(a, b)
|
||||
checkSubtype<B>(g)
|
||||
checkSubtype<A>(g)
|
||||
|
||||
// smart cast isn't needed, but is reported due to KT-4294
|
||||
val h: Any = two(a, b)
|
||||
|
||||
val k = three(a, b, c)
|
||||
checkSubtype<A>(k)
|
||||
<!INAPPLICABLE_CANDIDATE!>checkSubtype<!><B>(k)
|
||||
val l: Int = three(a, b, c)
|
||||
|
||||
use(d, e, f, g, h, k, l)
|
||||
}
|
||||
}
|
||||
|
||||
fun <T> foo(t: T, l: MutableList<T>): T = t
|
||||
|
||||
fun testErrorMessages(a: A, ml: MutableList<String>) {
|
||||
if (a is B && a is C) {
|
||||
<!INAPPLICABLE_CANDIDATE!>foo<!>(a, ml)
|
||||
}
|
||||
|
||||
if(a is C) {
|
||||
<!INAPPLICABLE_CANDIDATE!>foo<!>(a, ml)
|
||||
}
|
||||
}
|
||||
|
||||
fun rr(s: String?) {
|
||||
if (s != null) {
|
||||
val l = arrayListOf("", s)
|
||||
checkSubtype<MutableList<String>>(l)
|
||||
<!INAPPLICABLE_CANDIDATE!>checkSubtype<!><MutableList<String?>>(l)
|
||||
}
|
||||
}
|
||||
|
||||
//from library
|
||||
fun <T> arrayListOf(vararg values: T): MutableList<T> = throw Exception()
|
||||
|
||||
fun use(vararg a: Any) = a
|
||||
@@ -0,0 +1,11 @@
|
||||
// !CHECK_TYPE
|
||||
|
||||
fun foo(s : String?, b : Boolean) {
|
||||
if (s == null) return
|
||||
|
||||
val s1 = if (b) "" else s
|
||||
s1 checkType { <!UNRESOLVED_REFERENCE!>_<!><String>() }
|
||||
|
||||
val s2 = s
|
||||
s2 checkType { <!UNRESOLVED_REFERENCE!>_<!><String>() }
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
//KT-1355 Type inference fails with smartcast and generic function
|
||||
//tests for Map.set
|
||||
package a
|
||||
|
||||
import java.util.HashMap
|
||||
|
||||
fun foo(map: MutableMap<Int, String>, value: String?) {
|
||||
if (value != null) {
|
||||
map.put(1, value) //ok
|
||||
map.set(1, value) //type inference failed
|
||||
map[1] = value //type inference failed
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------
|
||||
|
||||
public data class Tag(public var tagName: String) {
|
||||
public val attributes: MutableMap<String, String> = HashMap<String, String>()
|
||||
public val contents: MutableList<Tag> = arrayListOf()
|
||||
|
||||
public var id: String?
|
||||
get() = attributes["id"]
|
||||
set(value) {
|
||||
if(value == null) {
|
||||
attributes.remove("id")
|
||||
}
|
||||
else {
|
||||
attributes["id"] = value!!
|
||||
attributes["id"] = value
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//from library
|
||||
operator fun <K, V> MutableMap<K, V>.set(key : K, value : V) = this.put(key, value)
|
||||
|
||||
fun <T> arrayListOf(vararg values: T): MutableList<T> = throw Exception()
|
||||
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// ISSUE: KT-25432
|
||||
|
||||
class Data<T>(val s: T)
|
||||
|
||||
fun test(d: Data<out Any>) {
|
||||
if (d.s is String) {
|
||||
d.s.length
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
//KT-2746 Do.smartcasts in inference
|
||||
|
||||
class C<T>(t :T)
|
||||
|
||||
fun test1(a: Any) {
|
||||
if (a is String) {
|
||||
val c: C<String> = C(a)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun <T> f(t :T): C<T> = C(t)
|
||||
|
||||
fun test2(a: Any) {
|
||||
if (a is String) {
|
||||
val c1: C<String> = f(a)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
//KT-2851 Type inference failed passing in not-null after smart-cast value in Pair
|
||||
package a
|
||||
|
||||
fun main() {
|
||||
val value: String? = ""
|
||||
if (value != null) {
|
||||
foo(Pair("val", value))
|
||||
foo(Pair("val", value!!))
|
||||
foo(Pair<String, String>("val", value))
|
||||
}
|
||||
}
|
||||
|
||||
fun foo(map: Pair<String, String>) {}
|
||||
|
||||
|
||||
//from library
|
||||
public class Pair<out A, out B> (
|
||||
public val first: A,
|
||||
public val second: B
|
||||
)
|
||||
@@ -0,0 +1,11 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// ISSUE: KT-29767
|
||||
|
||||
fun test(a: MutableList<out Int?>?) {
|
||||
if (a != null) {
|
||||
val b = a[0] // no SMARTCAST diagnostic
|
||||
if (b != null) {
|
||||
b.inc()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
interface PsiElement {
|
||||
fun getText(): String
|
||||
fun getParent(): PsiElement
|
||||
}
|
||||
|
||||
interface JetExpression : PsiElement
|
||||
|
||||
fun foo1(e: PsiElement) {
|
||||
var current: PsiElement? = e
|
||||
var first = true
|
||||
while (current != null) {
|
||||
if (current is JetExpression && first) {
|
||||
// Smartcast is possible here
|
||||
println(current.getText())
|
||||
}
|
||||
|
||||
current = current.getParent()
|
||||
}
|
||||
}
|
||||
|
||||
//from library
|
||||
fun println(any: Any?): Nothing = throw Exception("$any")
|
||||
@@ -0,0 +1,11 @@
|
||||
//KT-4403 Wrong "type mismatch" on smart cast with inference
|
||||
|
||||
interface A
|
||||
interface B : A
|
||||
|
||||
fun <T> T.f(): T = this
|
||||
|
||||
fun test(a: A) {
|
||||
if (a !is B) return
|
||||
val c = a.f() // type mismatch
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
//KT-4415 Class Auto-Cast Bug
|
||||
|
||||
interface SelfJson
|
||||
|
||||
object A {
|
||||
fun find(clz:Class<*>){ }
|
||||
|
||||
fun toJson2(obj:Any){
|
||||
if(obj is SelfJson){
|
||||
// A.find( (obj as SelfJson).javaClass) // OK
|
||||
A.find( obj.javaClass ) // ERROR: Type mismatch: inferred type is kotlin.Any but SelfJson was expected
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//from library
|
||||
val <T> T.javaClass : Class<T> get() = throw Exception()
|
||||
@@ -0,0 +1,12 @@
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE
|
||||
|
||||
inline fun<T> foo(block: () -> T):T = block()
|
||||
|
||||
fun baz() {
|
||||
val x: String = foo {
|
||||
val task: String? = null
|
||||
if (task == null) {
|
||||
return
|
||||
} else task
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
interface A
|
||||
interface B
|
||||
|
||||
class Test {
|
||||
fun test(a: A?, b: B, list: MutableList<Pair<A, B>>) {
|
||||
if (a != null) {
|
||||
list.add(a to b)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class Pair<out A, out B>(val first: A, val second: B)
|
||||
infix fun <A, B> A.to(that: B) = Pair(this, that)
|
||||
Reference in New Issue
Block a user