Introduce FIR_IDENTICAL for FIR vs old frontend tests #KT-36879 Fixed
This commit is contained in:
@@ -1,12 +0,0 @@
|
||||
//KT-1358 Overload resolution ambiguity with smartcast and generic function
|
||||
package d
|
||||
|
||||
fun bar(a: Any?) {
|
||||
if (a != null) {
|
||||
a.foo() //overload resolution ambiguity
|
||||
a.sure() //overload resolution ambiguity
|
||||
}
|
||||
}
|
||||
|
||||
fun <T : Any> T?.foo() {}
|
||||
fun <T : Any> T?.sure() : T = this!!
|
||||
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
//KT-1358 Overload resolution ambiguity with smartcast and generic function
|
||||
package d
|
||||
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
// !CHECK_TYPE
|
||||
|
||||
//KT-1944 Inference fails on run()
|
||||
package j
|
||||
|
||||
class P {
|
||||
var x : Int = 0
|
||||
private set
|
||||
|
||||
fun foo() {
|
||||
val r = run {x = 5} // ERROR
|
||||
checkSubtype<Unit>(r)
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// !CHECK_TYPE
|
||||
|
||||
//KT-1944 Inference fails on run()
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
// !CHECK_TYPE
|
||||
|
||||
//KT-2294 Type inference infers DONT_CARE instead of correct type
|
||||
package a
|
||||
|
||||
public fun <E> foo(array: Array<E>): Array<E> = array
|
||||
|
||||
public fun test()
|
||||
{
|
||||
val x = foo(array(1, 2, 3, 4, 5)) // Should infer type 'Int'
|
||||
// ^--- public final fun <T : kotlin.Any? > array(vararg t : DONT_CARE) : kotlin.Array<DONT_CARE> defined in Kotlin
|
||||
// ^--- public final fun <E : kotlin.Any? > foo(items t : kotlin.Array<DONT_CARE>) : kotlin.Array<DONT_CARE> defined in root package
|
||||
checkSubtype<Array<Int>>(x)
|
||||
}
|
||||
|
||||
//--------------------
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
fun <T> array(vararg t : T) : Array<T> = t as Array<T>
|
||||
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// !CHECK_TYPE
|
||||
|
||||
//KT-2294 Type inference infers DONT_CARE instead of correct type
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
//KT-2484 Type inferred for function literal is (...) -> Int instead of (...) -> Unit, when function literal parameter is explicit
|
||||
|
||||
package a
|
||||
//+JDK
|
||||
|
||||
fun <T> Array<T>.forEach(operation: (T) -> Unit) : Unit { for (element in this) operation(element) }
|
||||
|
||||
fun bar(operation: (String) -> Unit) = operation("")
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
args.forEach { a : String -> a.length } // Type mismatch: (String) -> Unit required, (String) -> Int found
|
||||
args.forEach { a -> a.length } // Type mismatch: (String) -> Unit required, (String) -> Int found
|
||||
args.forEach { it.length } // This works!
|
||||
|
||||
bar { a: String -> a.length }
|
||||
bar { a -> a.length }
|
||||
bar { it.length }
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
//KT-2484 Type inferred for function literal is (...) -> Int instead of (...) -> Unit, when function literal parameter is explicit
|
||||
|
||||
package a
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
// !CHECK_TYPE
|
||||
|
||||
//KT-2505 Type mismatch: inferred type is T but T was expected
|
||||
|
||||
package a
|
||||
|
||||
interface MyType {}
|
||||
class MyClass<T> : MyType {}
|
||||
|
||||
public open class HttpResponse() {
|
||||
public open fun <T> parseAs(dataClass : MyClass<T>) : T {
|
||||
throw Exception()
|
||||
}
|
||||
public open fun parseAs(dataType : MyType) : Any? {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
fun <R> test (httpResponse: HttpResponse, rtype: MyClass<R>) {
|
||||
val res = httpResponse.parseAs( rtype )
|
||||
checkSubtype<R>(res) //type mismatch: required R, found T
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// !CHECK_TYPE
|
||||
|
||||
//KT-2505 Type mismatch: inferred type is T but T was expected
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
//KT-2514 Type inference fails when using extension function literal
|
||||
package kt2514
|
||||
|
||||
//+JDK
|
||||
import java.io.Closeable
|
||||
|
||||
fun <T> Thread.use(block: Thread.() -> T): T = block()
|
||||
|
||||
fun <T: Closeable, R> T.use(block: (T)-> R) : R = block(this)
|
||||
|
||||
fun main() {
|
||||
Thread().use { } // compilation error: Type inference failed
|
||||
Thread().use { 5 + 5 } // compilation error: Type inference failed
|
||||
Thread().use<Unit> { } // compiles okay
|
||||
Thread().use<Int> { 5 + 5 } // compiles okay
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
//KT-2514 Type inference fails when using extension function literal
|
||||
package kt2514
|
||||
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE
|
||||
//T-2588 Allow to specify exact super type (expected) in inference if many
|
||||
|
||||
import java.util.HashSet
|
||||
|
||||
class MyClass<T>()
|
||||
|
||||
interface A
|
||||
interface D
|
||||
class B : A, D
|
||||
class C : A, D
|
||||
|
||||
fun <T> hashSetOf(vararg values: T): HashSet<T> = throw Exception("$values")
|
||||
|
||||
fun foo(b: MyClass<B>, c: MyClass<C>) {
|
||||
val set1 : Set<MyClass<out D>> = hashSetOf(b, c) //type inference expected type mismatch
|
||||
val set2 = hashSetOf(b, c) //Set<MyClass<out Any>> is inferred
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE
|
||||
//T-2588 Allow to specify exact super type (expected) in inference if many
|
||||
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
|
||||
package a
|
||||
|
||||
interface Closeable {
|
||||
fun close() {}
|
||||
}
|
||||
|
||||
class C : Closeable
|
||||
|
||||
public inline fun <T: Closeable, R> T.use(block: (t: T)-> R) : R {
|
||||
return block(this)
|
||||
}
|
||||
|
||||
fun test() {
|
||||
C().use {
|
||||
it.close()
|
||||
<!UNRESOLVED_REFERENCE!>x<!>
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// !WITH_NEW_INFERENCE
|
||||
|
||||
package a
|
||||
|
||||
-21
@@ -1,21 +0,0 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
|
||||
package a
|
||||
|
||||
interface Closeable {
|
||||
fun close() {}
|
||||
}
|
||||
|
||||
class C : Closeable
|
||||
|
||||
public inline fun <T: Closeable, R> use(t: T, block: T.(T)-> R) : R {
|
||||
return t.block(t)
|
||||
}
|
||||
|
||||
fun test() {
|
||||
use(C()) {
|
||||
this.close()
|
||||
it.close()
|
||||
<!UNRESOLVED_REFERENCE!>xx<!>
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// !WITH_NEW_INFERENCE
|
||||
|
||||
package a
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
|
||||
package a
|
||||
|
||||
interface Closeable {
|
||||
fun close() {}
|
||||
}
|
||||
|
||||
class C : Closeable
|
||||
|
||||
public inline fun <T: Closeable, R> T.use(block: T.()-> R) : R {
|
||||
return this.block()
|
||||
}
|
||||
|
||||
fun test() {
|
||||
C().use {
|
||||
this.close()
|
||||
<!UNRESOLVED_REFERENCE!>x<!>
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// !WITH_NEW_INFERENCE
|
||||
|
||||
package a
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
//KT-3174 Call resolver doesn't understand type is not-nullable after ?. safe call
|
||||
package a
|
||||
|
||||
fun <T: Any> T.test(): T = this
|
||||
fun foo(a: Any?) = a?.test() // Error
|
||||
|
||||
fun <T> T.fff(l: MutableList<T>) = l.add(this)
|
||||
|
||||
fun test(s: String?, l: MutableList<String>) {
|
||||
s?.fff(l)
|
||||
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
//KT-3174 Call resolver doesn't understand type is not-nullable after ?. safe call
|
||||
package a
|
||||
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
class Query<out T : Any> private constructor(
|
||||
private val result: T?,
|
||||
private val error: Throwable?,
|
||||
val inProgress: Boolean
|
||||
) {
|
||||
companion object {
|
||||
val inProgress = Query(null, null, true)
|
||||
fun forError(e: Throwable) = Query(null, e, false)
|
||||
fun <T : Any> forResult(result: T) = Query(result, null, false)
|
||||
}
|
||||
}
|
||||
|
||||
class MutableLiveData<T> {
|
||||
var value: Query<Int> = null!!
|
||||
}
|
||||
|
||||
fun main() {
|
||||
val liveData = MutableLiveData<Query<Int>>()
|
||||
liveData.value = Query.inProgress // Type mismatch: inferred type is Query<Any> but Query<Int> was expected
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
class Query<out T : Any> private constructor(
|
||||
private val result: T?,
|
||||
private val error: Throwable?,
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
//KT-3344 InternalError in compiler when type arguments are not specified
|
||||
|
||||
package i
|
||||
|
||||
import java.util.HashMap
|
||||
import java.util.ArrayList
|
||||
|
||||
class Foo(val attributes: Map<String, String>)
|
||||
|
||||
class Bar {
|
||||
val foos = ArrayList<Foo>()
|
||||
|
||||
fun bar11(foo: Foo) {
|
||||
foos.add(Foo(HashMap(foo.attributes))) // foo.attributes is unresolved but not marked
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
//KT-3344 InternalError in compiler when type arguments are not specified
|
||||
|
||||
package i
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
// !LANGUAGE: +NewInference
|
||||
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -CAST_NEVER_SUCCEEDS -UNUSED_VARIABLE
|
||||
// FILE: Test.java
|
||||
|
||||
class Test {
|
||||
static Number[] flexibleNumbers() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
|
||||
fun <T> foo(x: Array<out T>): T = x[0]
|
||||
|
||||
inline fun <reified T> materializeArray(): Array<T> = null as Array<T>
|
||||
|
||||
fun main() {
|
||||
val y = foo(Test.flexibleNumbers() ?: materializeArray()) // Any? in NI, Number! in OI (T of `materializeArray` is inferred to Any?)
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// !LANGUAGE: +NewInference
|
||||
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -CAST_NEVER_SUCCEEDS -UNUSED_VARIABLE
|
||||
// FILE: Test.java
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_ANONYMOUS_PARAMETER
|
||||
// KT-8132 Can't omit lambda parameter types
|
||||
|
||||
fun <T> test(foo: List<T>): T {
|
||||
return if (true)
|
||||
throw IllegalStateException()
|
||||
else
|
||||
foo.reduce { left, right -> left } // error: inferred type T is not subtype Nothing
|
||||
}
|
||||
|
||||
fun <S, T: S> Iterable<T>.reduce(operation: (S, T) -> S): S = throw Exception()
|
||||
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_ANONYMOUS_PARAMETER
|
||||
// KT-8132 Can't omit lambda parameter types
|
||||
|
||||
|
||||
Reference in New Issue
Block a user