[FIR-TEST] Add new testdata generated after changes in previous commit

This commit is contained in:
Dmitriy Novozhilov
2019-12-11 16:16:22 +03:00
parent e9c02a1cca
commit 2536fa0cd5
4578 changed files with 104067 additions and 1 deletions
@@ -0,0 +1,22 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
//KT-4372 Invalid error position and failing to resolve invoke with receiver from other module
class Foo<TInner, TOuter> {
fun invoke(content: TInner.() -> Unit) {
}
}
// comment this function to fix the error below
fun <TInner, TOuter> Foo<TInner, TOuter>.invoke(name: String, content: TInner.() -> Unit) {}
enum class EnumClass(val x: String) {}
object Y {
val x = javaClass<EnumClass>() // javaClass unresolved in any file in this module
}
//declarations from library
val <T> T.javaClass : Class<T>
get() = throw Exception()
fun <reified T> javaClass() : Class<T> = throw Exception()
@@ -0,0 +1,11 @@
// !WITH_NEW_INFERENCE
// !DIAGNOSTICS: -UNUSED_PARAMETER
fun Int.invoke(i: Int, a: Any) {}
fun Int.invoke(a: Any, i: Int) {}
fun foo(i: Int) {
<!AMBIGUITY!>i<!>(1, 1)
<!AMBIGUITY!>5(1, 2)<!>
}
@@ -0,0 +1,10 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
class My {
private operator fun Int.invoke(s: String) {}
}
fun My.foo(i: Int) {
<!INAPPLICABLE_CANDIDATE!>i<!>("")
<!INAPPLICABLE_CANDIDATE!>1("")<!>
}
@@ -0,0 +1,11 @@
fun test1(f: String.() -> Unit) {
<!INAPPLICABLE_CANDIDATE!>(f)()<!>
<!INAPPLICABLE_CANDIDATE!>f<!>()
}
fun test2(f: (Int) -> Int) {
1.<!UNRESOLVED_REFERENCE!>f<!>(2)
2.<!UNRESOLVED_REFERENCE!>(f)(2)<!>
}
@@ -0,0 +1,14 @@
// !WITH_NEW_INFERENCE
// !DIAGNOSTICS: -UNUSED_PARAMETER
class A<T>
operator fun <T> T.invoke(a: A<T>) {}
fun foo(s: String, ai: A<Int>) {
1(ai)
<!INAPPLICABLE_CANDIDATE!>s<!>(ai)
<!INAPPLICABLE_CANDIDATE!>""(ai)<!>
}
@@ -0,0 +1,5 @@
// !DIAGNOSTICS: -UNUSED_EXPRESSION
fun foo(i: Int) {
<!UNRESOLVED_REFERENCE!>i<!>()
<!UNRESOLVED_REFERENCE!>1()<!>
}
@@ -0,0 +1,10 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
// !WITH_NEW_INFERENCE
operator fun String.invoke(i: Int) {}
fun foo(s: String?) {
<!INAPPLICABLE_CANDIDATE!>s<!>(1)
<!INAPPLICABLE_CANDIDATE!>(s ?: null)(1)<!>
}
@@ -0,0 +1,17 @@
// !WITH_NEW_INFERENCE
fun test1() {
1. <!UNRESOLVED_REFERENCE!>(fun String.(i: Int) = i )(1)<!>
1.<!UNRESOLVED_REFERENCE!>(label@ fun String.(i: Int) = i )(1)<!>
}
fun test2(f: String.(Int) -> Unit) {
11.<!UNRESOLVED_REFERENCE!>(f)(1)<!>
11.<!UNRESOLVED_REFERENCE!>(f)()<!>
}
fun test3() {
fun foo(): String.(Int) -> Unit = {}
1.<!UNRESOLVED_REFERENCE!>(foo())(1)<!>
}
@@ -0,0 +1,10 @@
// !WITH_NEW_INFERENCE
// !DIAGNOSTICS: -UNUSED_PARAMETER
fun String.invoke(i: Int) {}
fun foo(i: Int) {
<!INAPPLICABLE_CANDIDATE!>i<!>(1)
<!INAPPLICABLE_CANDIDATE!>1(1)<!>
}
@@ -0,0 +1,23 @@
// !WITH_NEW_INFERENCE
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE
class A
fun test(foo: A.() -> Int, a: A) {
val b: Int = foo(a)
val c: Int = (foo)(a)
}
class B {
val foo: A.() -> Int = null!!
init {
val b: Int = foo(A())
}
}
fun foo(): A.() -> Int {
val b: Int = foo()(A())
val c: Int = (foo())(A())
return null!!
}
@@ -0,0 +1,14 @@
// !WITH_NEW_INFERENCE
// !DIAGNOSTICS: -UNUSED_PARAMETER
fun Int.invoke(a: Int) {}
fun Int.invoke(a: Int, b: Int) {}
class SomeClass
fun test(identifier: SomeClass, fn: String.() -> Unit) {
<!INAPPLICABLE_CANDIDATE!>identifier<!>()
<!INAPPLICABLE_CANDIDATE!>identifier<!>(123)
<!INAPPLICABLE_CANDIDATE!>identifier<!>(1, 2)
1.<!UNRESOLVED_REFERENCE!>fn<!>()
}
@@ -0,0 +1,33 @@
class B
class A {
operator fun B.invoke() = 4
}
class X {
operator fun invoke() = 3
}
fun test(a: A, b: B) {
with (a) {
b()
(b)()
}
X()()
val x = X()
x()
(x)()
}
fun test(c: () -> String, e: Int.() -> String) {
c()
(c)()
3.<!UNRESOLVED_REFERENCE!>e<!>()
3.<!UNRESOLVED_REFERENCE!>(e)()<!>
with(3) {
<!INAPPLICABLE_CANDIDATE!>e<!>()
<!INAPPLICABLE_CANDIDATE!>(e)()<!>
}
}
@@ -0,0 +1,22 @@
// !WITH_NEW_INFERENCE
class A(val x: (String.() -> Unit)?)
fun test(a: A) {
if (a.x != null) {
"".<!UNRESOLVED_REFERENCE!>(a.x)()<!>
a.x("") // todo
(a.x)("")
}
"".<!UNRESOLVED_REFERENCE!>(a.x)()<!>
a.<!INAPPLICABLE_CANDIDATE!>x<!>("")
<!INAPPLICABLE_CANDIDATE!>(a.x)("")<!>
with("") {
a.<!INAPPLICABLE_CANDIDATE!>x<!>()
<!INAPPLICABLE_CANDIDATE!>(a.x)()<!>
if (a.x != null) {
a.<!INAPPLICABLE_CANDIDATE!>x<!>() // todo
<!INAPPLICABLE_CANDIDATE!>(a.x)()<!>
}
}
}
@@ -0,0 +1,61 @@
class Foo {}
operator fun Foo.invoke() {}
//no variable
fun test(foo: Foo) {
foo()
}
//variable as member
interface A {
val foo: Foo
}
fun test(a: A) {
a.foo()
with (a) {
foo()
}
}
//variable as extension
interface B {
}
val B.foo: Foo
get() = Foo()
fun test(b: B) {
b.foo()
with (b) {
foo()
}
}
//variable as member extension
interface C
interface D {
val C.foo: Foo
fun test(c: C) {
c.foo()
with (c) {
foo()
}
}
}
fun test(d: D, c: C) {
with (d) {
c.foo()
with (c) {
foo()
}
}
}
@@ -0,0 +1,60 @@
class Foo {
operator fun invoke() {}
}
//no variable
fun test(foo: Foo) {
foo()
}
//variable as member
interface A {
val foo: Foo
}
fun test(a: A) {
a.foo()
with (a) {
foo()
}
}
//variable as extension
interface B {}
val B.foo: Foo
get() = Foo()
fun test(b: B) {
b.foo()
with (b) {
foo()
}
}
//variable as member extension
interface C
interface D {
val C.foo: Foo
fun test(c: C) {
c.foo()
with (c) {
foo()
}
}
}
fun test(d: D, c: C) {
with (d) {
c.foo()
with (c) {
foo()
}
}
}
@@ -0,0 +1,123 @@
class Foo
//no variable
interface A {
operator fun Foo.invoke() {}
fun test(foo: Foo) {
foo()
}
}
//variable as member
interface B {
val foo: Foo
}
class C {
operator fun Foo.invoke() {}
fun test(b: B) {
b.foo()
with (b) {
foo()
}
}
}
fun test(c: C, b: B) {
with (c) {
b.foo()
with (b) {
foo()
}
}
}
//variable as extension,
interface D {
}
val D.foo: Foo
get() = Foo()
class E {
operator fun Foo.invoke() {}
fun test(d: D) {
d.foo()
with (d) {
foo()
}
}
}
fun test(e: E, d: D) {
with (e) {
d.foo()
with (d) {
foo()
}
}
}
//variable as member extension
interface F
interface G {
val F.foo: Foo
operator fun Foo.invoke()
fun test(f: F) {
f.foo()
with (f) {
foo()
}
}
}
fun test(g: G, f: F) {
with (g) {
f.foo()
with (f) {
foo()
}
}
}
//variable as member extension (2)
interface X
interface U {
val X.foo: Foo
}
interface V {
operator fun Foo.invoke() {}
fun U.test(x: X) {
x.foo()
with (x) {
foo()
}
}
}
fun test(u: U, v: V, x: X) {
with (v) {
with (u) {
x.foo()
with (x) {
foo()
}
}
}
}
@@ -0,0 +1,12 @@
interface A
interface Foo {
operator fun A.invoke()
}
fun test(a: A, foo: Foo) {
a.<!UNRESOLVED_REFERENCE!>foo<!>()
}
fun test(a: Int, foo: Int.()->Unit) {
a.<!UNRESOLVED_REFERENCE!>foo<!>()
}
@@ -0,0 +1,7 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_ANONYMOUS_PARAMETER
class C {
fun f() {}
}
fun C.g(f: (String) -> Unit = { s -> f() }) {}
@@ -0,0 +1,84 @@
// !WITH_NEW_INFERENCE
// FILE: 1.kt
package fooIsExtension
class A
class B
val A.foo: B.() -> Unit get() = {}
fun test(a: A, b: B) {
b.<!UNRESOLVED_REFERENCE!>(a.foo)()<!>
(a.foo)(b)
a.foo(b)
with(a) {
b.<!UNRESOLVED_REFERENCE!>foo<!>()
b.<!UNRESOLVED_REFERENCE!>(foo)()<!>
<!UNRESOLVED_REFERENCE!>(b.<!INAPPLICABLE_CANDIDATE!>foo<!>)()<!>
foo(b)
(foo)(b)
}
with(b) {
a.<!INAPPLICABLE_CANDIDATE!>foo<!>()
a.<!UNRESOLVED_REFERENCE!>(foo)()<!>
<!INAPPLICABLE_CANDIDATE!>(a.foo)()<!>
(a.foo)(this)
a.foo(this)
}
with(a) {
with(b) {
<!INAPPLICABLE_CANDIDATE!>foo<!>()
<!INAPPLICABLE_CANDIDATE!>(foo)()<!>
}
}
}
// FILE: 1.kt
package fooIsMember
class A {
val foo: B.() -> Unit get() = {}
}
class B
fun test(a: A, b: B) {
b.<!UNRESOLVED_REFERENCE!>(a.foo)()<!>
(a.foo)(b)
a.foo(b)
with(a) {
b.<!UNRESOLVED_REFERENCE!>foo<!>()
b.<!UNRESOLVED_REFERENCE!>(foo)()<!>
<!UNRESOLVED_REFERENCE!>(b.<!UNRESOLVED_REFERENCE!>foo<!>)()<!>
foo(b)
(foo)(b)
}
with(b) {
a.<!INAPPLICABLE_CANDIDATE!>foo<!>()
a.<!UNRESOLVED_REFERENCE!>(foo)()<!>
<!INAPPLICABLE_CANDIDATE!>(a.foo)()<!>
(a.foo)(this)
a.foo(this)
}
with(a) {
with(b) {
<!INAPPLICABLE_CANDIDATE!>foo<!>()
<!INAPPLICABLE_CANDIDATE!>(foo)()<!>
}
}
}
@@ -0,0 +1,27 @@
//KT-3772 Invoke and overload resolution ambiguity
package bar
open class A {
public operator fun invoke(f: A.() -> Unit) {}
}
class B {
public operator fun invoke(f: B.() -> Unit) {}
}
open class C
val C.attr: A
get() = A()
open class D: C()
val D.attr: B
get() = B()
fun main() {
val b = D()
b.attr {} // overload resolution ambiguity
val d = b.attr
d {} // no error
}
@@ -0,0 +1,35 @@
//KT-3833 Invoke method not working inside companion object?
package m
class Either1 {
class Left() {
fun match(left: () -> Unit) {
left()
}
}
inner class Right() {
fun match(right: () -> Unit) {
right()
}
}
}
class X {
operator fun invoke() {
}
}
object Foo{
val v : X = X()
}
class C{
companion object {
fun f(){
Foo.v()
}
}
}
@@ -0,0 +1,24 @@
//KT-4204 ConstraintSystem erased after resolution completion
package c
public abstract class TestBug1() {
public fun m3(position: Int) {
position(m1().second!!)
}
public fun m4(position: (Int)->Int) {
position(m1().second)
}
private abstract fun m1(): Pair<Int, Int>
private fun position(p: Int) {}
}
//from library
public class Pair<out A, out B> (
public val first: A,
public val second: B
)
@@ -0,0 +1,35 @@
//KT-4321 invoke() on enum doesn't work
import DOMElementTestClasses.cls2
// use case 1
enum class DOMElementTestClasses {
cls1, cls2;
operator fun invoke() {}
}
// use case 2
interface EnumStyleClass {
operator fun invoke() {}
}
enum class TestClasses : EnumStyleClass {
cls
}
// example
fun main() {
// Kotlin: Expression 'cls1' of type 'DOMElementTestClasses' cannot be invoked as a function
DOMElementTestClasses.cls1()
// Kotlin: Expression 'cls2' of type 'DOMElementTestClasses' cannot be invoked as a function
cls2()
// Kotlin: Expression 'cls' of type 'TestClasses' cannot be invoked as a function
TestClasses.cls()
// All ok
val cls = DOMElementTestClasses.cls2
cls()
}
@@ -0,0 +1,16 @@
//KT-9517 Wrong resolve for invoke convention after smart cast
open class A {
open val foo: () -> Number = null!!
}
class B: A() {
override val foo: () -> Int
get() = null!!
}
fun test(a: A) {
if (a is B) {
val foo: Int = a.foo() // B::foo + invoke()
}
}
@@ -0,0 +1,17 @@
class A {
val foo: B.() -> Unit get() = null!!
}
class B
fun test(a: A, b: B) {
with(b) {
a.<!INAPPLICABLE_CANDIDATE!>foo<!>() // here must be error, because a is not extension receiver
a.foo(this)
<!INAPPLICABLE_CANDIDATE!>(a.foo)()<!>
(a.foo)(this)
}
}
@@ -0,0 +1,13 @@
// !WITH_NEW_INFERENCE
// !DIAGNOSTICS: -UNUSED_PARAMETER
fun Int.invoke() {}
class SomeClass
fun test(identifier: SomeClass, fn: String.() -> Unit) {
<!INAPPLICABLE_CANDIDATE!>identifier<!>()
<!INAPPLICABLE_CANDIDATE!>identifier<!>(123)
<!INAPPLICABLE_CANDIDATE!>identifier<!>(1, 2)
1.<!UNRESOLVED_REFERENCE!>fn<!>()
}
@@ -0,0 +1,9 @@
interface A
fun foo(invoke: A.()->Unit, a: A) {
a.<!UNRESOLVED_REFERENCE!>invoke<!>()
}
fun bar(invoke: Any.()->Any, a: Any) {
a.<!UNRESOLVED_REFERENCE!>invoke<!>()
}
@@ -0,0 +1,18 @@
class B
class A {
operator fun B.invoke() {}
}
val B.a: () -> Int get() = { 5 }
fun test(a: A, b: B) {
val x: Int = b.a()
b.<!UNRESOLVED_REFERENCE!>(a)()<!>
with(b) {
val y: Int = <!UNRESOLVED_REFERENCE!>a<!>()
<!UNRESOLVED_REFERENCE!>(a)()<!>
}
}