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,17 +0,0 @@
// !CHECK_TYPE
fun test(bal: Array<Int>) {
var bar = 4
val a = { bar += 4 }
checkSubtype<() -> Unit>(a)
val b = { bar = 4 }
checkSubtype<() -> Unit>(b)
val c = { bal[2] = 3 }
checkSubtype<() -> Unit>(c)
val d = run { bar += 4 }
checkSubtype<Unit>(d)
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !CHECK_TYPE
fun test(bal: Array<Int>) {
@@ -1,53 +0,0 @@
// !CHECK_TYPE
// !DIAGNOSTICS: -UNUSED_PARAMETER
class A
operator fun A.component1() = 1
operator fun A.component2() = ""
class B
class D {
operator fun A.component1() = 1.0
operator fun A.component2() = ' '
operator fun B.component1() = 1.0
operator fun B.component2() = ' '
}
fun foo(block: (A) -> Unit) { }
fun foobaz(block: D.(B) -> Unit) { }
fun foobar(block: D.(A) -> Unit) { }
fun bar() {
foo { (a, b) ->
a checkType { _<Int>() }
b checkType { _<String>() }
}
foo { (a: Int, b: String) ->
a checkType { _<Int>() }
b checkType { _<String>() }
}
// From KEEP: Component-functions are resolved in the same scope as the first statement of the lambda
foobaz { (a, b) ->
a checkType { _<Double>() }
b checkType { _<Char>() }
}
// From KEEP: Component-functions are resolved in the same scope as the first statement of the lambda
// So `component1`/`component2` for lambda parameters were resolved to member extensions
foobar { (a, b) ->
a checkType { _<Double>() }
b checkType { _<Char>() }
}
// the following code fails with exception, see KT-13873
// foobarbaz {
// component1: B.() -> Int,
// component2: B.() -> String,
// (a, b): B ->
//
// }
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !CHECK_TYPE
// !DIAGNOSTICS: -UNUSED_PARAMETER
class A
@@ -1,25 +0,0 @@
// !CHECK_TYPE
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE
data class A(val x: Int, val y: String)
fun foo(block: (A) -> Unit) { }
fun bar(a: Double) {
val b = 1.toShort()
// Do not report NAME_SHADOWING on lambda destructured parameter, the same way as for common parameters
foo { (a, b) ->
a checkType { _<Int>() }
b checkType { _<String>() }
}
foo { (c, d) ->
c checkType { _<Int>() }
d checkType { _<String>() }
foo { (a, c) ->
a checkType { _<Int>() }
c checkType { _<String>() }
d checkType { _<String>() }
}
}
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !CHECK_TYPE
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE
data class A(val x: Int, val y: String)
@@ -1,15 +0,0 @@
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_EXPRESSION
import java.util.HashSet
fun test123() {
val g: (Int) -> Unit = if (true) {
val set = HashSet<Int>()
fun (i: Int) {
set.add(i)
}
}
else {
{ it -> it }
}
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_EXPRESSION
import java.util.HashSet
@@ -1,15 +0,0 @@
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_EXPRESSION
import java.util.HashSet
fun test123() {
val g: (Int) -> Unit = if (true) {
val set = HashSet<Int>();
{ i ->
set.add(i)
}
}
else {
{ it -> it }
}
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_EXPRESSION
import java.util.HashSet
@@ -1,11 +0,0 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
fun <T> Iterable<T>.filter(predicate: (T) -> Boolean): List<T> = TODO()
operator fun <T> Collection<T>.plus(elements: Iterable<T>): List<T> = TODO()
fun stringCollection(): Collection<String> = TODO()
fun <K> test(c: Collection<K>) {
var variants = stringCollection()
variants += variants.filter { true }
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_PARAMETER
fun <T> Iterable<T>.filter(predicate: (T) -> Boolean): List<T> = TODO()
@@ -1,22 +0,0 @@
//KT-2906 If function parameter/variable is invoked in closure using parenthesis syntax, in IDEA it is not highlighted as captured in closure
package bug
public fun foo1(bar: () -> Unit) {
run {
bar() // ERROR: not highlighted as "captured in closure"
}
}
public fun foo2(bar: () -> Unit) {
run {
bar.invoke() // CORRECT: highlighted as "captured in closure"
}
}
fun main() {
foo1 { println ("foo1")} // prints "foo1"
foo2 { println ("foo2")} // prints "foo2"
}
fun println(s: String) = s
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
//KT-2906 If function parameter/variable is invoked in closure using parenthesis syntax, in IDEA it is not highlighted as captured in closure
package bug
@@ -1,14 +0,0 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
// !LANGUAGE: +NewInference
// SKIP_TXT
// Issue: KT-35168
class Inv<T>
// Before the fix, here we had an exception while fixing a type variable for Inv due to prematurely analyzing a lambda
// The exception was: "UninitializedPropertyAccessException: lateinit property subResolvedAtoms has not been initialized"
class Foo<T>(x: (T) -> T, y: Inv<Any>)
fun bar() {
Foo<Any>({}, Inv())
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_PARAMETER
// !LANGUAGE: +NewInference
// SKIP_TXT
@@ -1,9 +0,0 @@
val flag = true
interface I
class A(): I
class B(): I
val a = l@ {
return@l if (flag) A() else B()
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
val flag = true
interface I
@@ -1,17 +0,0 @@
val flag = true
val a /*: (Int) -> String */ = l@ {
i: Int ->
if (i == 0) return@l i.toString()
"Ok"
}
fun <T> foo(f: (Int) -> T): T = f(0)
val b /*:String */ = foo {
i ->
if (i == 0) return@foo i.toString()
"Ok"
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
val flag = true
val a /*: (Int) -> String */ = l@ {
@@ -1,6 +0,0 @@
// !CHECK_TYPE
fun test2() {
val x = run f@{return@f 1}
checkSubtype<Int>(x)
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !CHECK_TYPE
fun test2() {
@@ -1,12 +0,0 @@
// !CHECK_TYPE
fun test() {
val x = run(f@{return@f 1})
checkSubtype<Int>(x)
}
fun test1() {
val x = run(l@{return@l 1})
checkSubtype<Int>(x)
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !CHECK_TYPE
fun test() {
@@ -1,12 +0,0 @@
// !CHECK_TYPE
fun test() {
val x = run f@{
fun local(a: Int): String {
if (a > 0) return "2"
return@local "3"
}
return@f 1
}
checkSubtype<Int>(x)
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !CHECK_TYPE
fun test() {
@@ -1,11 +0,0 @@
// !CHECK_TYPE
fun test() {
val x = run f@{
run ff@ {
return@ff "2"
}
return@f 1
}
checkSubtype<Int>(x)
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !CHECK_TYPE
fun test() {
@@ -1,14 +0,0 @@
class A
val flag = true
val a /*: () -> A?*/ = l@ {
if (flag) return@l null
A()
}
val b /*: () -> A?*/ = l@ {
if (flag) return@l null
return@l A()
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
class A
val flag = true
@@ -1,9 +0,0 @@
// !CHECK_TYPE
fun test(a: Int) {
val x = run f@{
if (a > 0) return@f
else return@f Unit
}
checkSubtype<Unit>(x)
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !CHECK_TYPE
fun test(a: Int) {
@@ -1,16 +0,0 @@
val flag = true
// type of lambda was checked by txt
val a = l@ { // () -> Any
if (flag) return@l 4
return@l Unit
}
val b = l@ { // () -> Any
if (flag) return@l Unit
5
}
val c = l@ { // () -> Unit
if (flag) return@l Unit
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
val flag = true
// type of lambda was checked by txt
@@ -1,14 +0,0 @@
// !CHECK_TYPE
interface A
interface B: A
interface C: A
fun test(a: C, b: B) {
val x = run f@{
if (a != b) return@f a
b
}
checkSubtype<A>(x)
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !CHECK_TYPE
interface A
@@ -1,10 +0,0 @@
package m
interface Element
fun test(handlers: Map<String, Element.()->Unit>) {
handlers.getOrElse("name", { null })
}
fun <K,V> Map<K,V>.getOrElse(key: K, defaultValue: ()-> V) : V = throw Exception("$key $defaultValue")
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
package m
interface Element