Introduce FIR_IDENTICAL for FIR vs old frontend tests #KT-36879 Fixed

This commit is contained in:
Mikhail Glukhikh
2020-03-04 17:54:33 +03:00
parent 186e0b0cba
commit 8884cbe415
2268 changed files with 1175 additions and 19754 deletions
@@ -1,25 +0,0 @@
// JAVAC_EXPECTED_FILE
// FILE: java/util/Collection.java
package java.util;
public class Collection {
public void foo() {}
}
// FILE: test/Usage.java
package test;
import java.util.*;
public class Usage {
void foo(Collection c) {
c.foo();
}
}
// FILE: Kotlin.kt
package test
fun foo(u: Usage) {
u.foo(null)
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// JAVAC_EXPECTED_FILE
// FILE: java/util/Collection.java
package java.util;
@@ -1,10 +0,0 @@
// NI_EXPECTED_FILE
interface In<in E>
class En<T> : In<T>
class A : In<A>
fun <T> select(x: T, y: T): T = x ?: y
// Return type should be In<*> nor In<out Any?>
fun foobar(e: En<*>) = select(A(), e)
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// NI_EXPECTED_FILE
interface In<in E>
@@ -1,9 +0,0 @@
// NI_EXPECTED_FILE
interface In<in E>
class A : In<A>
class B : In<B>
fun <T> select(x: T, y: T) = x ?: y
// Return type should be In<*> nor In<out Any?>
fun foobar(a: A, b: B) = select(a, b)
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// NI_EXPECTED_FILE
interface In<in E>
@@ -1,15 +0,0 @@
class A<T> {
fun foo() {
val q = object {
open inner class B
inner class C : B()
// No WRONG_NUMBER_OF_TYPE_ARGUMENTS should be reported on these types
val x: B = B()
val y: C = C()
}
q.x
q.y
}
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
class A<T> {
fun foo() {
val q = object {
@@ -1,9 +0,0 @@
open class Super<T> {
inner open class Inner {
}
}
class Sub : Super<String>() {
// TODO: it would be nice to have a possibility to omit explicit type argument in supertype
inner class SubInner : Super<String>.Inner() {}
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
open class Super<T> {
inner open class Inner {
}
@@ -1,12 +0,0 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
open class Super<T> {
inner open class Inner {
}
}
class Sub : Super<String>() {
inner class SubInner : Super<String>.Inner {
constructor()
constructor(x: Int) : super() {}
}
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_PARAMETER
open class Super<T> {
inner open class Inner {
@@ -1,18 +0,0 @@
// !DIAGNOSTICS: -UNUSED_VARIABLE
open class Super<T> {
inner open class Inner {
open fun getOuter(): Super<T> = throw UnsupportedOperationException()
}
}
class Sub<T1>(): Super<T1>() {
inner class SubInner : Super<T1>.Inner() { // 'Inner' is unresolved
// Also, T1 is not resolved to anything, and not marked as resolved
init {
val x: Super<T1>.Inner = this // T1 is not resolved to anything
}
override fun getOuter(): Sub<T1> = throw UnsupportedOperationException()
}
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_VARIABLE
open class Super<T> {
@@ -1,12 +0,0 @@
// !DIAGNOSTICS: -UNUSED_VARIABLE
interface T<E> {
fun f() : E = null!!
}
open class A<X>() {
inner class B() : T<X> {}
}
fun test() {
val a = A<Int>()
val b : A<Int>.B = a.B()
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_VARIABLE
interface T<E> {
fun f() : E = null!!
@@ -1,37 +0,0 @@
// !CHECK_TYPE
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER
class Outer<out E> {
inner class Inner {
fun foo() = this
fun baz(): Inner = this
}
fun bar() = Inner()
// Should be unsafe variance error here
fun set(inner: Inner) {}
}
fun factoryString(): Outer<String>.Inner = null!!
fun <T> infer(x: T): Outer<T>.Inner = null!!
val inferred = infer("")
fun main() {
val outer = Outer<String>()
checkSubtype<Outer<String>.Inner>(outer.bar())
checkSubtype<Outer<String>.Inner>(outer.Inner())
checkSubtype<Outer<*>.Inner>(outer.bar())
checkSubtype<Outer<*>.Inner>(outer.Inner())
checkSubtype<Outer<CharSequence>.Inner>(outer.bar())
checkSubtype<Outer<CharSequence>.Inner>(outer.Inner())
outer.set(outer.bar())
outer.set(outer.Inner())
val x: Outer<String>.Inner = factoryString()
outer.set(x)
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !CHECK_TYPE
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER
@@ -1 +0,0 @@
class C<T : C<T>>
@@ -1 +1,2 @@
// FIR_IDENTICAL
class C<T : C<T>>
@@ -1,2 +0,0 @@
class C<T>
fun <T : C<T>> foo() {}
@@ -1,2 +1,3 @@
// FIR_IDENTICAL
class C<T>
fun <T : C<T>> foo() {}
@@ -1,18 +0,0 @@
public interface Collector<T, R>
class A<out T> {
fun foo(): T = null!!
}
public fun <T> toList(): Collector<T, A<T>> = null!!
interface Stream<T> {
public fun <R> collect(collector: Collector<in T, R>): R
}
fun stream(): Stream<String> = null!!
fun main() {
val stream: Stream<String> = stream()
val xs = stream.collect(toList())
xs.foo()
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
public interface Collector<T, R>
class A<out T> {
@@ -1,17 +0,0 @@
// FILE: First.java
public class First<T extends Sample> {
public static <D extends Sample> void bind(First<D> first) {}
}
// FILE: SubFirst.java
public class SubFirst<D extends Sample> extends First<D> {}
// FILE: test.kt
interface Sample
fun test(s: SubFirst<*>) {
First.bind(s)
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// FILE: First.java
public class First<T extends Sample> {
@@ -1,17 +0,0 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
// FILE: JClass.java
public class JClass {
public <K> void foo(Key<K> key, K value) {}
}
// FILE: test.kt
class Key<T>
fun <S> select(x: S, y: S): S = x
fun <T> setValue(key: Key<T>, value: T, j: JClass) {
j.foo(key, select(value, null))
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_PARAMETER
// FILE: JClass.java
@@ -1,14 +0,0 @@
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_PARAMETER
abstract class Expr<T>
class Sum<K>(val e: Expr<K>) : Expr<K?>()
private fun <V> times(e: Expr<V>, element: V): Expr<V> = TODO()
private fun <S> foo(e: Expr<S>) {}
fun test(intExpression: Expr<Int>) {
foo(Sum(times(intExpression, 42)))
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_PARAMETER
@@ -1,13 +0,0 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
class A<T> {
fun foo() = 1
}
interface B
public fun <E : B> E.bar() : A<out E> = null!!
fun baz(x: B) {
x.bar().foo()
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_PARAMETER
class A<T> {
@@ -1,16 +0,0 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_ANONYMOUS_PARAMETER
// !CHECK_TYPE
// FILE: Clazz.java
public class Clazz<Psi> {
public java.util.Collection<Psi> foo() { return null; }
}
// FILE: main.kt
public fun <T, C : MutableCollection<in T>> Iterable<T>.filterTo(destination: C, predicate: (T) -> Boolean) {}
fun test(clazz: Clazz<out Any>) {
val result = java.util.ArrayList<Any>()
clazz.foo().filterTo(result) { x -> true }
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_ANONYMOUS_PARAMETER
// !CHECK_TYPE
@@ -1,11 +0,0 @@
class A<T>
fun <T> A<T>.foo(): Collection<T> = null!!
fun main(a: A<*>, a1: A<out CharSequence>) {
// see KT-9571
for (i in a.foo()) { }
for (i: Any? in a.foo()) { }
for (i in a1.foo()) { }
for (i: CharSequence in a1.foo()) { }
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
class A<T>
fun <T> A<T>.foo(): Collection<T> = null!!
@@ -1,8 +0,0 @@
interface Subscriber<T>
interface Observable<T> {
fun subscribe(s: Subscriber<in T>)
}
fun foo(o: Observable<out CharSequence>, y: Subscriber<in CharSequence>) = o.subscribe(y) // type safe
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
interface Subscriber<T>
interface Observable<T> {
@@ -1,12 +0,0 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
// See KT-7296
interface Out<out F>
interface B<T> : Out<Out<T>>
fun foo(x : B<*>) {
bar1(x)
bar2(x)
}
fun bar1(x : Out<Out<*>>) { }
fun bar2(x : Out<*>) { }
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_PARAMETER
// See KT-7296
interface Out<out F>
@@ -1,11 +0,0 @@
// !DIAGNOSTICS: -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE
interface Rec<T>
class A : Rec<A>
class B : Rec<B>
fun test(a: A, b: B, c: Boolean) {
var ab = if (c) a else b
ab = a
ab = b
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE
interface Rec<T>
@@ -1,7 +0,0 @@
// Tests that generic bounds in the object supertype are resolved prior to the supertype itself
object O : Tr<V<*>>
interface Tr<T>
class V<out S>
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// Tests that generic bounds in the object supertype are resolved prior to the supertype itself
object O : Tr<V<*>>
@@ -1,15 +0,0 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
fun <R> foo(x: R, y: String) {}
fun <R> foo(x: R, y: R) {
foo<R>(x, "") // ok, resolved foo(x: R, y: String)
foo(x, "") // ok, foo(x: R, y: String)
foo<R>(x, x) // ok, resolved foo(x: R, y: R)
foo(x, x) // ok, resolved foo(x: R, y: R)
}
class Q<R>(x: R) {
fun foo() {
Q<R>("")
}
}
fun <R> Q(x: String) {}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_PARAMETER
fun <R> foo(x: R, y: String) {}
fun <R> foo(x: R, y: R) {
@@ -1,3 +0,0 @@
class A<T : A<T>>
fun <T : A<*>> foo() {}
class B<T : A<*>>
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
class A<T : A<T>>
fun <T : A<*>> foo() {}
class B<T : A<*>>
@@ -1,14 +0,0 @@
// FILE: p/Base.java
package p;
import java.util.*;
public class Base<T> {
void coll(Collection<?> r) {}
}
// FILE: k.kt
package p
class Derived: p.Base<String>()
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// FILE: p/Base.java
package p;
@@ -1,14 +0,0 @@
// FILE: p/Base.java
package p;
public class Base<T> {
void foo(R<?> r) {}
}
// FILE: k.kt
package p
class R<T: R<T>>
class Derived: p.Base<String>()
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// FILE: p/Base.java
package p;
@@ -1,9 +0,0 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
class R<T: R<T>>
open class Base<T> {
fun foo(r: R<*>) {}
}
class Derived: Base<String>()
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_PARAMETER
class R<T: R<T>>
@@ -1,24 +0,0 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
inline fun <reified T> foo() {}
inline fun <reified F> bar() {
foo<Array<F>>()
foo<List<F>>()
}
inline fun <reified E> baz(x: E) {}
fun test(x: Array<String>, y: Array<*>) {
foo<List<String>>()
foo<List<*>>()
foo<Map<*, String>>()
foo<Map<*, *>>()
foo<Array<String>>()
foo<Array<*>>()
baz(x)
baz(y)
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_PARAMETER
inline fun <reified T> foo() {}
@@ -1,8 +0,0 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
inline fun<T1, reified T2> bar(x: T1, y: T2): T2 = y
inline fun<reified R> foo(z: R): R = bar(1, z)
fun box() {
foo("abc")
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_PARAMETER
inline fun<T1, reified T2> bar(x: T1, y: T2): T2 = y