KT-11203: report errors on read-write operations for elements of collections with inconsistent get&set signatures

This commit is contained in:
Dmitry Petrov
2016-03-01 17:37:45 +03:00
parent cd91e44451
commit 3ca4097bcc
7 changed files with 128 additions and 6 deletions
@@ -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() {
++MismatchingTypes<!NO_SET_METHOD!>[0]<!>
MismatchingTypes<!NO_SET_METHOD!>[0]<!>++
MismatchingTypes<!NO_SET_METHOD!>[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() {
++MismatchingArities1<!NO_SET_METHOD!>[0]<!>
MismatchingArities1<!NO_SET_METHOD!>[0]<!>++
MismatchingArities1<!NO_SET_METHOD!>[0]<!> += 1
++<!NO_VALUE_FOR_PARAMETER!>MismatchingArities2[0]<!>
<!NO_VALUE_FOR_PARAMETER!>MismatchingArities2[0]<!>++
<!NO_VALUE_FOR_PARAMETER!>MismatchingArities2[0]<!> += 1
}
@@ -0,0 +1,42 @@
package
public fun testLegal(): kotlin.Unit
public fun testMismatchingArities(): kotlin.Unit
public fun testMismatchingTypes(): kotlin.Unit
public object Legal {
private constructor Legal()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public final operator fun get(/*0*/ i: kotlin.Int): kotlin.Int
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public final operator fun set(/*0*/ i: kotlin.Int, /*1*/ newValue: kotlin.Int): kotlin.Unit
public final operator fun set(/*0*/ i: kotlin.Int, /*1*/ newValue: kotlin.String): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public object MismatchingArities1 {
private constructor MismatchingArities1()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public final operator fun get(/*0*/ i: kotlin.Int): kotlin.Int
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public final operator fun set(/*0*/ i: kotlin.Int, /*1*/ j: kotlin.Int, /*2*/ newValue: kotlin.Int): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public object MismatchingArities2 {
private constructor MismatchingArities2()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public final operator fun get(/*0*/ i: kotlin.Int, /*1*/ j: kotlin.Int): kotlin.Int
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public final operator fun set(/*0*/ i: kotlin.Int, /*1*/ newValue: kotlin.Int): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public object MismatchingTypes {
private constructor MismatchingTypes()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public final operator fun get(/*0*/ i: kotlin.Int): kotlin.Int
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public final operator fun set(/*0*/ i: kotlin.Int, /*1*/ newValue: kotlin.String): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}