[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,17 @@
//KT-1820 Write test for ASSIGN_OPERATOR_AMBIGUITY
package kt1820
class MyInt(val i: Int) {
operator fun plus(m: MyInt) : MyInt = MyInt(m.i + i)
}
operator fun Any.plusAssign(a: Any) {}
fun test(m: MyInt) {
m += m
var i = 1
<!ASSIGN_OPERATOR_AMBIGUITY!>i += 34<!>
}
@@ -0,0 +1,40 @@
class A {
operator fun plusAssign(x: Int) {}
operator fun minusAssign(x: Int) {}
operator fun timesAssign(x: Int) {}
operator fun divAssign(x: Int) {}
operator fun remAssign(x: Int) {}
}
fun testVal() {
val a = A()
a += 1
a -= 1
a *= 1
a /= 1
a %= 1
}
fun testExpr() {
A() += 1
A() -= 1
A() *= 1
A() /= 1
A() %= 1
}
class B {
operator fun plus(x: Int): B = B()
operator fun minus(x: Int): B = B()
operator fun times(x: Int): B = B()
operator fun div(x: Int): B = B()
operator fun rem(x: Int): B = B()
}
fun testWrong() {
<!VARIABLE_EXPECTED!>B()<!> += 1
<!VARIABLE_EXPECTED!>B()<!> -= 1
<!VARIABLE_EXPECTED!>B()<!> *= 1
<!VARIABLE_EXPECTED!>B()<!> /= 1
<!VARIABLE_EXPECTED!>B()<!> %= 1
}
@@ -0,0 +1,45 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
object Legal {
operator fun get(i: Int) = 0
operator fun set(i: Int, newValue: Int) {}
operator fun set(i: Int, newValue: String) {}
}
fun testLegal() {
++Legal[0]
Legal[0]++
Legal[0] += 1
}
object MismatchingTypes {
operator fun get(i: Int) = 0
operator fun set(i: Int, newValue: String) {}
}
fun testMismatchingTypes() {
<!INAPPLICABLE_CANDIDATE!>++MismatchingTypes[0]<!>
<!INAPPLICABLE_CANDIDATE!>MismatchingTypes[0]++<!>
MismatchingTypes[0] += 1
}
object MismatchingArities1 {
operator fun get(i: Int) = 0
operator fun set(i: Int, j: Int, newValue: Int) {}
}
object MismatchingArities2 {
operator fun get(i: Int, j: Int) = 0
operator fun set(i: Int, newValue: Int) {}
}
fun testMismatchingArities() {
<!INAPPLICABLE_CANDIDATE!>++MismatchingArities1[0]<!>
<!INAPPLICABLE_CANDIDATE!>MismatchingArities1[0]++<!>
MismatchingArities1[0] += 1
<!UNRESOLVED_REFERENCE!>++<!><!INAPPLICABLE_CANDIDATE!>MismatchingArities2[0]<!>
<!INAPPLICABLE_CANDIDATE!>MismatchingArities2[0]<!><!UNRESOLVED_REFERENCE!>++<!>
MismatchingArities2[0] += 1
}
@@ -0,0 +1,27 @@
//KT-1821 Write test for ITERATOR_AMBIGUITY diagnostic
interface MyCollectionInterface {
}
interface MyAnotherCollectionInterface {
}
class MyCollection : MyCollectionInterface, MyAnotherCollectionInterface {
}
fun MyCollectionInterface.iterator() = MyIterator()
fun MyAnotherCollectionInterface.iterator() = MyIterator()
class MyIterator {
fun next() : MyElement = MyElement()
fun hasNext() = true
}
class MyElement
fun test1(collection: MyCollection) {
collection.<!AMBIGUITY!>iterator<!>()
<!AMBIGUITY, UNRESOLVED_REFERENCE, UNRESOLVED_REFERENCE!>for (element in collection) {
}<!>
}
@@ -0,0 +1,48 @@
fun intBinEq() {
var x = 0
<!UNRESOLVED_REFERENCE!>x += 'a'<!>
x += 1.toByte()
x += 1.toShort()
x += 1L
<!UNRESOLVED_REFERENCE!>x += 1f<!>
<!UNRESOLVED_REFERENCE!>x += 1.0<!>
<!UNRESOLVED_REFERENCE!>x *= 'a'<!>
<!UNRESOLVED_REFERENCE!>x *= 1.toByte()<!>
<!UNRESOLVED_REFERENCE!>x *= 1.toShort()<!>
<!UNRESOLVED_REFERENCE!>x *= 1L<!>
<!UNRESOLVED_REFERENCE!>x *= 1f<!>
<!UNRESOLVED_REFERENCE!>x *= 1.0<!>
}
fun shortBinEq() {
var x = 0.toShort()
<!UNRESOLVED_REFERENCE!>x += 'a'<!>
x += 1.toByte()
<!UNRESOLVED_REFERENCE!>x += 1.toShort()<!>
<!UNRESOLVED_REFERENCE!>x += 1L<!>
<!UNRESOLVED_REFERENCE!>x += 1f<!>
<!UNRESOLVED_REFERENCE!>x += 1.0<!>
<!UNRESOLVED_REFERENCE!>x *= 'a'<!>
<!UNRESOLVED_REFERENCE!>x *= 1.toByte()<!>
<!UNRESOLVED_REFERENCE!>x *= 1.toShort()<!>
<!UNRESOLVED_REFERENCE!>x *= 1L<!>
<!UNRESOLVED_REFERENCE!>x *= 1f<!>
<!UNRESOLVED_REFERENCE!>x *= 1.0<!>
}
class A {
operator fun plus(x : A) : A { return x }
}
class B {
operator fun plus(x : A) : A { return x }
}
fun overloading() {
var x = A()
var y = A()
x += y
var z = B()
z += x
}
@@ -0,0 +1,12 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
class C {
operator fun compareTo(c: C): Int? = null
}
fun test(c: C) {
c < c
c <= c
c >= c
c > c
}
@@ -0,0 +1,35 @@
//KT-1028 Wrong type checking for plusAssign
package kt1028
import java.util.*
class event<T>()
{
val callbacks = ArrayList< Function1<T, Unit> >() // Should be ArrayList<()->Unit>, bug posted
operator fun plusAssign(f : (T) -> Unit) = callbacks.add(f)
operator fun minusAssign(f : (T) -> Unit) = callbacks.remove(f)
fun call(value : T) { for(c in callbacks) c(value) }
}
class MouseMovedEventArgs()
{
public val X : Int = 0
}
class Control()
{
public val MouseMoved : event<MouseMovedEventArgs> = event<MouseMovedEventArgs>()
fun MoveMouse() = MouseMoved.call(MouseMovedEventArgs())
}
class Test()
{
fun test()
{
val control = Control()
control.MouseMoved += { <!UNRESOLVED_REFERENCE!>it<!>.<!UNRESOLVED_REFERENCE!>X<!> } // here
control.MouseMoved.plusAssign( { it.X } ) // ok
}
}
@@ -0,0 +1,13 @@
// !WITH_NEW_INFERENCE
class A {
operator fun get(x: Int): Int = x
fun set(x: Int, y: Int) {} // no `operator` modifier
}
fun main() {
val a = A()
a[1]++
a[1] += 3
a[1] = a[1] + 3
}
@@ -0,0 +1,4 @@
// !WITH_NEW_INFERENCE
//KT-13330 AssertionError: Illegal resolved call to variable with invoke
fun foo(exec: (String.() -> Unit)?) = "".<!UNRESOLVED_REFERENCE!>exec<!><caret>() // <caret> is test data tag here
@@ -0,0 +1,7 @@
object Foo {
operator fun <T> invoke() {}
}
fun main() {
<!INAPPLICABLE_CANDIDATE!>Foo<!><Int>()
}
@@ -0,0 +1,23 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
public class A {
public operator fun get(vararg attrs : Pair<String, String>) : A = this
}
operator fun String.unaryPlus() : A = A()
operator fun A.div(s : String) : A = A()
fun test() {
(+"node2" / "node3" / "zzz") ["attr" to "value", "a2" to "v2"]
}
//---------
class B {
public operator fun get(s : String, q : String) : B = this
public operator fun get(s : Pair<String, String>) : B = this
public operator fun invoke(q : B.() -> Unit) : B = this
}
val x = B()["a", "v"]["a" to "b"] {} ["q" to "p"] // does not parses around {}
//from library
data class Pair<out A, out B> (val first: A, val second: B)
infix fun <A,B> A.to(that: B) = Pair(this, that)
@@ -0,0 +1,20 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
class C {
operator fun get(i: Int): C = this
}
operator fun C.plus(a: Any): C = this
operator fun C.plusAssign(a: Any) {}
class C1 {
operator fun get(i: Int): C = C()
operator fun set(i: Int, v: C) {}
}
fun test() {
val c = C()
c[0] += ""
var c1 = C1()
c1[0] += ""
}
@@ -0,0 +1,13 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
class C
operator fun C.plus(a: Any): C = this
operator fun C.plusAssign(a: Any) {}
fun test() {
val c = C()
c += ""
var c1 = C()
<!ASSIGN_OPERATOR_AMBIGUITY!>c1 += ""<!>
}
@@ -0,0 +1,19 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
class C {
val c: C = C()
}
operator fun C.plus(a: Any): C = this
operator fun C.plusAssign(a: Any) {}
class C1 {
var c: C = C()
}
fun test() {
val c = C()
c.c += ""
var c1 = C1()
<!ASSIGN_OPERATOR_AMBIGUITY!>c1.c += ""<!>
}