[FIR-TEST] Add new testdata generated after changes in previous commit
This commit is contained in:
+16
@@ -0,0 +1,16 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
class Out<out T>
|
||||
class In<in T>
|
||||
class Inv<T>
|
||||
|
||||
fun <R> choose1(c: Out<Out<R>>) {}
|
||||
fun <R> choose2(c: In<In<R>>) {}
|
||||
fun <R> choose3(c: Inv<Inv<R>>) {}
|
||||
|
||||
fun f(o: Out<Out<*>>, i: In<In<*>>, inv: Inv<Inv<*>>) {
|
||||
choose1(o)
|
||||
choose2(i)
|
||||
<!INAPPLICABLE_CANDIDATE!>choose3<!>(inv)
|
||||
}
|
||||
Vendored
+12
@@ -0,0 +1,12 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
package c
|
||||
|
||||
import java.util.ArrayList
|
||||
|
||||
fun Array<Int>.toIntArray(): IntArray = this.<!INAPPLICABLE_CANDIDATE!>mapTo<!>(IntArray(size), {<!UNRESOLVED_REFERENCE!>it<!>})
|
||||
|
||||
fun Array<Int>.toArrayList(): ArrayList<Int> = this.mapTo(ArrayList<Int>(size), {it})
|
||||
|
||||
public fun <T, R, C: MutableCollection<in R>> Array<out T>.mapTo(result: C, transform : (T) -> R) : C =
|
||||
throw Exception("$result $transform")
|
||||
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_EXPRESSION
|
||||
|
||||
class Inv<T>(val x: T?)
|
||||
|
||||
fun <K> create(y: K) = Inv(y)
|
||||
fun <K> createPrivate(y: K) = Inv(y)
|
||||
|
||||
fun takeInvInt(i: Inv<Int>) {}
|
||||
|
||||
fun <S> test(i: Int, s: S) {
|
||||
val a = Inv(s)
|
||||
|
||||
a
|
||||
|
||||
val b = create(i)
|
||||
|
||||
b
|
||||
|
||||
val c = createPrivate(i)
|
||||
|
||||
c
|
||||
|
||||
takeInvInt(create(i))
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
interface Parent
|
||||
interface Inv<T>
|
||||
|
||||
object Child : Parent
|
||||
|
||||
fun <K : Parent> wrapper(): Inv<K> = TODO()
|
||||
fun <T : Parent> consume(wrapper: Inv<T>) {}
|
||||
|
||||
fun <S> select(x: S, y: S): S = x
|
||||
|
||||
fun error(f: Inv<out Parent>, w: Inv<Child>) {
|
||||
consume(select(f, wrapper<Child>()))
|
||||
}
|
||||
Vendored
+19
@@ -0,0 +1,19 @@
|
||||
// !CHECK_TYPE
|
||||
interface A<T>
|
||||
|
||||
fun <T> foo(a: A<T>, aN: A<T?>): T = throw Exception("$a $aN")
|
||||
|
||||
fun <T> doA(a: A<T>): T = throw Exception("$a")
|
||||
|
||||
fun test(a: A<Int>, aN: A<Int?>) {
|
||||
val aa = doA(aN)
|
||||
aa checkType { <!UNRESOLVED_REFERENCE!>_<!><Int?>() }
|
||||
|
||||
val nullable = foo(aN, aN)
|
||||
//T = Int?, T? = Int? => T = Int?
|
||||
nullable checkType { <!UNRESOLVED_REFERENCE!>_<!><Int?>() }
|
||||
|
||||
val notNullable = foo(a, aN)
|
||||
//T = Int, T? = Int? => T = Int
|
||||
notNullable checkType { <!UNRESOLVED_REFERENCE!>_<!><Int>() }
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
// !LANGUAGE: +NewInference
|
||||
|
||||
// FILE: Sam.java
|
||||
|
||||
public interface Sam<K> {
|
||||
Sam.Result<K> compute();
|
||||
|
||||
public static class Result<V> {
|
||||
public static <V> Sam.Result<V> create(V value) {}
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: Foo.java
|
||||
|
||||
public class Foo {
|
||||
public static <T> void foo(Sam<T> var1) {
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
fun test(e: ErrorType) {
|
||||
Foo.foo {
|
||||
Sam.Result.<!INAPPLICABLE_CANDIDATE!>create<!>(e)
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
class Inv<T>
|
||||
|
||||
fun <K> foo(t: K?) = Inv<K>()
|
||||
|
||||
fun <T> bar(t: T) = foo(t)
|
||||
fun <V1> bar1(t: V1): Inv<V1> = foo(t)
|
||||
fun <V2> bar2(t: V2): Inv<V2> = foo(t)
|
||||
|
||||
fun <S> select(x: S, y: S): S = x
|
||||
|
||||
fun <T> fail(t: T?) = if (t == null) bar(t) else bar(t)
|
||||
fun <F> fail1(t: F?, n: Nothing?) = select(bar1(n), bar2(t!!))
|
||||
fun <F> fail2(t: F?, n: Nothing?) = if (t == null) bar1(t) else bar2(t)
|
||||
fun <F> fail3(t: F?) = select(bar1(null), bar2(t?.let { it }))
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// !CHECK_TYPE
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE
|
||||
|
||||
class Foo<T>
|
||||
|
||||
fun <T> foo1(f: (T) -> Unit): Foo<T> = Foo()
|
||||
inline fun <reified T> foo2(f: (T) -> Unit): Foo<T> = Foo()
|
||||
|
||||
fun test1() {
|
||||
val f1: Foo<out Int> = foo1 { it checkType { _<Int>() } }
|
||||
val f2: Foo<in Nothing> = foo1 { it checkType { _<Nothing>() } }
|
||||
|
||||
val f3: Foo<out Int> = foo2 { it checkType { _<Int>() } }
|
||||
val f4: Foo<in Nothing> = foo2 { it checkType { _<Nothing>() } }
|
||||
}
|
||||
compiler/testData/diagnostics/tests/inference/constraints/inferTypeFromCapturedStarProjection.fir.kt
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
interface Box<out R>
|
||||
fun <R> List<Box<R>>.choose(): Box<R>? = TODO()
|
||||
fun list(): List<Box<*>> = TODO()
|
||||
|
||||
fun f() = list().choose()
|
||||
@@ -0,0 +1,21 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE
|
||||
// AssertionError in ConstraintSystem(The constraint shouldn't contain different type variables on both sides: Y <: X)
|
||||
|
||||
class A<X, Y : X>
|
||||
|
||||
class B<X, Y : X>(foo: A<X, Y>) {
|
||||
fun test1(a: A<X, Y>) {
|
||||
B(a)
|
||||
val b: B<X, Y> = B(a)
|
||||
// crash here
|
||||
}
|
||||
}
|
||||
|
||||
class C<X, Z, Y : X>
|
||||
|
||||
class D<X, Z, Y : X>(foo: C<X, Z, Y>) {
|
||||
fun test(a: C<Y, Y, Y>) {
|
||||
val d: D<X, Y, Y> = D(a)
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
package kt7351
|
||||
|
||||
interface Node
|
||||
|
||||
interface Source<T> {
|
||||
fun f() : T
|
||||
}
|
||||
fun <T, S : Source<T>> S.woo() : T = this.f()
|
||||
|
||||
fun Node.append(block : Source<Int>.() -> Unit) {
|
||||
}
|
||||
|
||||
fun crashMe(node : Node) {
|
||||
node.append {
|
||||
woo()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE
|
||||
|
||||
public inline fun <S, T: S> Iterable<T>.reduce1(operation: (S, T) -> S): S = throw Exception()
|
||||
|
||||
fun test(ints: List<Int>) {
|
||||
val f: () -> Unit = {
|
||||
ints.reduce1 { a, b -> a + b }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
interface Inv<I>
|
||||
interface Inv2<I>
|
||||
|
||||
fun <T: Inv2<T>> foo(klass: Inv<T>): String? = null
|
||||
|
||||
fun <X> bar(): Inv<X> = null!!
|
||||
|
||||
fun test() {
|
||||
foo(bar())
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// SKIP_JAVAC
|
||||
|
||||
// FILE: MySettings.java
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public class MySettings<
|
||||
SS extends MySettings<SS, PS, L>,
|
||||
PS extends MyComparableSettings,
|
||||
L extends MySettingsListener<PS>
|
||||
>
|
||||
{
|
||||
public Collection<PS> getLinkedProjectsSettings() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static MySettings getSettings() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
abstract class MyComparableSettings implements Comparable<MyComparableSettings> {}
|
||||
abstract class MySettingsListener<S extends MyComparableSettings> {}
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
fun test() {
|
||||
val a = MySettings.getSettings()
|
||||
a.getLinkedProjectsSettings()
|
||||
a.linkedProjectsSettings
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// SKIP_JAVAC
|
||||
|
||||
// FILE: MySettings.java
|
||||
|
||||
import java.util.Collection
|
||||
|
||||
class MySettings<
|
||||
SS extends MySettings<SS, PS, L>,
|
||||
PS extends MyComparableSettings,
|
||||
L extends MySettingsListener<PS>
|
||||
>
|
||||
{
|
||||
public Collection<PS> getLinkedProjectsSettings() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static MySettings<?, ?, ?> getSettings() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
abstract class MyComparableSettings implements Comparable<MyComparableSettings> {}
|
||||
abstract class MySettingsListener<S extends MyComparableSettings> {}
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
fun test() {
|
||||
val a = MySettings.getSettings()
|
||||
a.getLinkedProjectsSettings()
|
||||
a.linkedProjectsSettings
|
||||
}
|
||||
Vendored
+25
@@ -0,0 +1,25 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// !CHECK_TYPE
|
||||
interface A<T>
|
||||
|
||||
interface In<in T>
|
||||
|
||||
interface Out<out T>
|
||||
|
||||
fun <T: Any> doT(t: T?): T = throw Exception("$t")
|
||||
fun <T: Any> doOut(o: Out<T?>): T { throw Exception("$o") }
|
||||
fun <T: Any> doIn(i: In<T?>) { throw Exception("$i") }
|
||||
fun <T: Any> doA(i: A<T?>) { throw Exception("$i") }
|
||||
|
||||
fun test(out: Out<Int>, i: In<Int>, inv: A<Int>) {
|
||||
// T? >: Int => T = Int
|
||||
doT(1)
|
||||
val r = doOut(out)
|
||||
r checkType { <!UNRESOLVED_REFERENCE!>_<!><Int>() }
|
||||
|
||||
// T? <: Int => error
|
||||
<!INAPPLICABLE_CANDIDATE!>doIn<!>(i)
|
||||
|
||||
// T? >: Int => error
|
||||
<!INAPPLICABLE_CANDIDATE!>doA<!>(inv)
|
||||
}
|
||||
Vendored
+9
@@ -0,0 +1,9 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
fun test() {
|
||||
generateException(Data(1), { Data(it.x + 2) })
|
||||
}
|
||||
|
||||
fun <T> generateException(a: T, next: (T) -> T) {}
|
||||
|
||||
class Data<out K>(val x: K)
|
||||
compiler/testData/diagnostics/tests/inference/constraints/recursiveJavaTypeWithStarProjection.fir.kt
Vendored
+22
@@ -0,0 +1,22 @@
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE
|
||||
// !LANGUAGE: +NewInference
|
||||
|
||||
// FILE: MenuItemBase.java
|
||||
|
||||
public class MenuItemBase<C extends ContextMenuBase<C, I, S>, I extends MenuItemBase<C, I, S>, S extends SubMenuBase<C, I, S>> {
|
||||
public String getText() { return null; }
|
||||
}
|
||||
|
||||
// FILE: ContextMenuBase.java
|
||||
|
||||
public class ContextMenuBase<C extends ContextMenuBase<C, I, S>, I extends MenuItemBase<C, I, S>, S extends SubMenuBase<C, I, S>> {}
|
||||
|
||||
// FILE: SubMenuBase.java
|
||||
|
||||
public class SubMenuBase<C extends ContextMenuBase<C, I, S>, I extends MenuItemBase<C, I, S>, S extends SubMenuBase<C, I, S>> {}
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
fun test(m: MenuItemBase<*, *, *>) {
|
||||
m.text
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
// !LANGUAGE: +NewInference
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER -CAST_NEVER_SUCCEEDS
|
||||
// SKIP_TXT
|
||||
|
||||
// FILE: Test.java
|
||||
import java.util.Collection;
|
||||
|
||||
public class Test {
|
||||
static <T> Inv<Collection<? extends T>> bar() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
class Inv<E>
|
||||
|
||||
fun <R> foo(x: R, y: Inv<R>) {}
|
||||
|
||||
fun main() {
|
||||
val values: List<Int> = null as List<Int>
|
||||
/*
|
||||
* Before the fix, there was type mismatch during checking `Test.bar()` to pass to `foo`:
|
||||
* Required: Inv<List<Int>>
|
||||
* Found: Inv<(MutableCollection<out Int!>..Collection<Int!>?)>
|
||||
* Constraint `(MutableCollection<out T!>..Collection<T!>?)` from 'Found' (for TypeVariable(R)) has been removed
|
||||
* during fixation TypeVariable(T) due to the constraint for R contained TypeVariable(T).
|
||||
* The problem was that TypeVariable(T) wan't substituted due to `containsConstrainingTypeWithoutProjection` optimization.
|
||||
*/
|
||||
foo(values, Test.bar())
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE
|
||||
|
||||
fun testLambda() {
|
||||
val basicTest: (Int) -> Int = myRun {
|
||||
val x: Any? = null
|
||||
if (x is String) return@myRun { it -> x.length <!AMBIGUITY!>+<!> it }
|
||||
if (x !is Int) return@myRun { it -> it }
|
||||
|
||||
{ it -> x + it }
|
||||
}
|
||||
|
||||
val twoLambda: (Int) -> Int = myRun {
|
||||
val x: Int = 1
|
||||
run {
|
||||
val y: Int = 2
|
||||
{ x + y }
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
inline fun <R> myRun(block: () -> R): R = block()
|
||||
Vendored
+22
@@ -0,0 +1,22 @@
|
||||
// !CHECK_TYPE
|
||||
interface A<T>
|
||||
|
||||
interface Out<out T>
|
||||
|
||||
fun <T> foo(a: A<T>, o: Out<T?>): T = throw Exception("$a $o")
|
||||
|
||||
fun <T> doOut(o: Out<T?>): T = throw Exception("$o")
|
||||
|
||||
fun test(a: A<Int>, aN: A<Int?>, o: Out<Int?>) {
|
||||
val out = doOut(o)
|
||||
//T? >: Int? => T >: Int
|
||||
out checkType { <!UNRESOLVED_REFERENCE!>_<!><Int>() }
|
||||
|
||||
val nullable = foo(aN, o)
|
||||
//T = Int?, T? >: Int? => T = Int?
|
||||
nullable checkType { <!UNRESOLVED_REFERENCE!>_<!><Int?>() }
|
||||
|
||||
val notNullable = foo(a, o)
|
||||
//T = Int, T? >: Int? => T = Int
|
||||
notNullable checkType { <!UNRESOLVED_REFERENCE!>_<!><Int>() }
|
||||
}
|
||||
Vendored
+22
@@ -0,0 +1,22 @@
|
||||
// !CHECK_TYPE
|
||||
interface A<T>
|
||||
|
||||
interface In<in T>
|
||||
|
||||
fun <T> foo(a: A<T>, i: In<T>): T = throw Exception("$a $i")
|
||||
|
||||
fun <T> doIn(i: In<T?>): T = throw Exception("$i")
|
||||
|
||||
fun test(a: A<Int>, aN: A<Int?>, i: In<Int?>) {
|
||||
val _in = doIn(i)
|
||||
//T? <: Int? => T <: Int?
|
||||
_in checkType { <!UNRESOLVED_REFERENCE!>_<!><Int?>() }
|
||||
|
||||
val notNullable = foo(a, i)
|
||||
//T = Int, T? <: Int? => T = Int
|
||||
notNullable checkType { <!UNRESOLVED_REFERENCE!>_<!><Int>() }
|
||||
|
||||
val nullable = foo(aN, i)
|
||||
//T = Int?, T? <: Int? => T = Int?
|
||||
nullable checkType { <!UNRESOLVED_REFERENCE!>_<!><Int?>() }
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
class Foo {
|
||||
var test: String by refreshOnUpdate("str")
|
||||
|
||||
fun <T> refreshOnUpdate(initialValue: T) = RefreshDelegate(initialValue)
|
||||
|
||||
class RefreshDelegate<T>(initialValue: T?) {
|
||||
operator fun getValue(thisRef: Foo, property: KProperty<*>): T = TODO()
|
||||
|
||||
operator fun setValue(thisRef: Foo, property: KProperty<*>, value: T) {}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user