[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,76 @@
// !WITH_NEW_INFERENCE
// FILE: b.kt
package outer
fun Int?.optint() : Unit {}
val Int?.optval : Unit get() = Unit
fun <T: Any, E> T.foo(x : E, y : A) : T {
y.plus(1)
y plus 1
y + 1.0
this?.minus<T>(this)
return this
}
class A
infix operator fun A.plus(a : Any) {
1.foo()
true.<!INAPPLICABLE_CANDIDATE!>foo<!>()
1
}
operator fun A.plus(a : Int) {
1
}
operator fun <T> T.minus(t : T) : Int = 1
fun test() {
val y = 1.abs
}
val Int.abs : Int
get() = if (this > 0) this else -this;
val <T> T.foo : T
fun Int.foo() = this
// FILE: b.kt
package null_safety
import outer.*
fun parse(cmd: String): Command? { return null }
class Command() {
// fun equals(other : Any?) : Boolean
val foo : Int = 0
}
fun Any.equals(other : Any?) : Boolean = true
fun Any?.equals1(other : Any?) : Boolean = true
fun Any.equals2(other : Any?) : Boolean = true
fun main() {
System.out.print(1)
val command = parse("")
command.foo
command.<!INAPPLICABLE_CANDIDATE!>equals<!>(null)
command?.equals(null)
command.equals1(null)
command?.equals1(null)
val c = Command()
c?.equals2(null)
if (command == null) 1
}
@@ -0,0 +1,22 @@
interface T {
fun foo() {}
fun buzz() {}
fun buzz1(i : Int) {}
}
fun T.bar() {}
fun T.buzz() {}
fun T.buzz1() {}
class C : T {
fun test() {
fun T.buzz() {}
fun T.buzz1() {}
super.foo() // OK
super.bar() // Error
super.buzz() // OK, resolved to a member
super.buzz1() // Resolved to an extension
super.<!INAPPLICABLE_CANDIDATE!>buzz1<!>("") // Resolved to a member
}
}
@@ -0,0 +1,36 @@
import java.util.Enumeration
fun <T> java.util.Enumeration<T>.iterator() = object: Iterator<T> {
override fun hasNext(): Boolean = hasMoreElements()
override fun next() = nextElement()
}
interface MyIterator<T> {
operator fun hasNext() : Boolean
operator fun next() : T
}
operator fun <T : Any> T?.iterator() = object : MyIterator<T> {
var hasNext = this@iterator != null
private set
override fun hasNext() = hasNext
override fun next() : T {
if (hasNext) {
hasNext = false
return this@iterator!!
}
throw java.util.<!UNRESOLVED_REFERENCE!>NoSuchElementException<!>()
}
}
fun main() {
val i : Int? = 1
for (x in i) {
System.out.println(x)
}
}
@@ -0,0 +1,15 @@
// !CHECK_TYPE
import java.util.Enumeration
operator fun <T> java.util.Enumeration<T>.iterator() = object : Iterator<T> {
public override fun hasNext(): Boolean = hasMoreElements()
public override fun next() = nextElement()
}
fun a(e : java.util.Enumeration<Int>) {
for (i in e) {
<!INAPPLICABLE_CANDIDATE!>checkSubtype<!><Int>(i)
}
}
@@ -0,0 +1,20 @@
// !WITH_NEW_INFERENCE
interface Tr
class A { companion object }
class B { companion object : Tr }
fun Any.f1() {}
fun Any?.f2() {}
fun Tr.f3() {}
fun Tr?.f4() {}
fun A.f5() {}
fun test() {
A.f1()
A.f2()
B.f3()
B.f4()
A.<!INAPPLICABLE_CANDIDATE!>f5<!>()
B.<!INAPPLICABLE_CANDIDATE!>f5<!>()
}
@@ -0,0 +1,18 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
interface JPAEntityClass<D> {
fun <T> T.findByName(s: String): D {null!!}
}
class Foo {
companion object : JPAEntityClass<Foo>
}
fun main() {
with("", {
Foo.<!UNRESOLVED_REFERENCE!>findByName<!>("")
})
with(Foo) {
findByName("")
}
}
@@ -0,0 +1,8 @@
val Int.foo: Int
get() = this
fun test(foo: Int) {
test(4.foo)
test(foo)
}
@@ -0,0 +1,22 @@
// !WITH_NEW_INFERENCE
//KT-1875 Safe call should be binded with receiver or this object (but not with both by default)
package kt1875
fun foo(a : Int?, b : Int.(Int)->Int) = a?.<!UNRESOLVED_REFERENCE!>b<!>(1) //unnecessary safe call warning
interface T {
val f : ((i: Int) -> Unit)?
}
fun test(t: T) {
t.<!INAPPLICABLE_CANDIDATE!>f<!>(1) //unsafe call error
t.f?.invoke(1)
}
fun test1(t: T?) {
t.<!UNRESOLVED_REFERENCE!>f<!>(1) // todo resolve f as value and report UNSAFE_CALL
t?.f(1)
t.<!INAPPLICABLE_CANDIDATE!>f<!>?.<!UNRESOLVED_REFERENCE!>invoke<!>(1)
t?.f?.invoke(1)
}
@@ -0,0 +1,15 @@
//KT-2317 Wrong UNNECESSARY_SAFE_CALL
package kt2317
fun Any?.baz() = 1
fun foo(l: Long?) = l?.baz()
fun Any?.bar(): Unit { }
fun quux(x: Int?): Unit {
x?.baz()
x?.bar()
}
@@ -0,0 +1,7 @@
class A {
companion object {
fun foo() = toString()
}
}
val a = A.toString()
@@ -0,0 +1,17 @@
// !WITH_NEW_INFERENCE
// KT-3563 Compiler requiring java.io.File, and it's unclear why
package bar
import java.io.File
class Customer(name1: String)
fun foo(f: File, c: Customer) {
f.name1
c.<!INAPPLICABLE_CANDIDATE!>name1<!> // name1 should be unresolved here
}
val File.name1: String
get() = getName()
@@ -0,0 +1,37 @@
//KT-819 Redeclaration error for extension properties with the same name and different receivers
// FULL_JDK
import java.io.*
val InputStream.buffered : BufferedInputStream
get() = if(this is BufferedInputStream) this else BufferedInputStream(this)
val Reader.buffered : BufferedReader
get() = if(this is BufferedReader) this else BufferedReader(this)
//more tests
open class A() {
open fun String.foo() {}
open fun Int.foo() {}
open val String.foo: Int
get() = 0
open val Int.foo: Int
get() = 1
}
class B() : A() {
override fun String.foo() {}
override fun Int.foo() {}
override val String.foo: Int
get() = 0
override val Int.foo: Int
get() = 0
fun use(s: String) {
s.foo
s.foo()
}
}
@@ -0,0 +1,11 @@
// FILE: A.java
public class A {
public static void foo() {}
public static class Nested {}
}
// FILE: B.kt
fun Any?.bar() = 42
fun f1() = A.bar()
fun f2() = A.Nested.bar()
@@ -0,0 +1,6 @@
object O
fun Any.foo() = 42
val Any?.bar: Int get() = 239
val x = O.foo() + O.bar
@@ -0,0 +1,56 @@
// !WITH_NEW_INFERENCE
package bar
// should be thrown away
fun <R> List<R>.a() {}
fun test1(i: Int?) {
1.<!INAPPLICABLE_CANDIDATE!>a<!>()
i.<!INAPPLICABLE_CANDIDATE!>a<!>()
}
fun <R> test2(c: Collection<R>) {
c.<!INAPPLICABLE_CANDIDATE!>a<!>()
}
fun Int.foo() {}
fun test3(s: String?) {
"".<!INAPPLICABLE_CANDIDATE!>foo<!>()
s.<!INAPPLICABLE_CANDIDATE!>foo<!>()
"".<!INAPPLICABLE_CANDIDATE!>foo<!>(1)
s.<!INAPPLICABLE_CANDIDATE!>foo<!>("a")
}
interface A
fun <T: A> T.c() {}
fun test4() {
1.<!INAPPLICABLE_CANDIDATE!>c<!>()
}
// should be an error on receiver, shouldn't be thrown away
fun test5() {
1.<!UNRESOLVED_REFERENCE!>(fun String.()=1)()<!>
}
fun <R: Any> R?.sure() : R = this!!
fun <T> test6(l: List<T>?) {
l.<!INAPPLICABLE_CANDIDATE!>sure<!><T>()
}
fun List<String>.b() {}
fun test7(l: List<String?>) {
l.<!INAPPLICABLE_CANDIDATE!>b<!>()
}
fun test8(l: List<Any>?) {
l.<!INAPPLICABLE_CANDIDATE!>b<!>()
}
@@ -0,0 +1,15 @@
// !WITH_NEW_INFERENCE
package a
class A {}
fun test(a1: A, a2: A) {
val range = "island".."isle"
a1<!INAPPLICABLE_CANDIDATE!>..<!>a2
}
public operator fun <T: Comparable<T>> T.rangeTo(that: T): ClosedRange<T> {
throw UnsupportedOperationException()
}
@@ -0,0 +1,11 @@
class A(foo: Int.() -> Unit) {
init {
4.<!UNRESOLVED_REFERENCE!>foo<!>()
}
}
fun test(foo: Int.(String) -> Unit) {
4.<!UNRESOLVED_REFERENCE!>foo<!>("")
4.<!UNRESOLVED_REFERENCE!>foo<!>(p1 = "")
4.<!UNRESOLVED_REFERENCE!>foo<!>(p2 = "")
}