Files
kotlin-fork/compiler/testData/diagnostics/tests/operatorsOverloading/InconsistentGetSet.fir.kt
T
vladislav.grechko 9aa8fb80e7 Set correct IR origins for inc/dec operations
NB: in order to produce correct IR origins, the source element kinds for
some FIR elements has been changed. As a side effect, mapping PSI to FIR
slightly changed: namely, for `a[b]++`, `a[b]` used to be mapped on
`set` call or callable reference, but now it is mapped on `get` call.

^KT-61891: Fixed
^KT-64387: Fixed
2024-01-30 14:26:10 +00:00

46 lines
1.2 KiB
Kotlin
Vendored

// !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() {
<!ARGUMENT_TYPE_MISMATCH!>++MismatchingTypes[0]<!>
<!ARGUMENT_TYPE_MISMATCH!>MismatchingTypes[0]++<!>
MismatchingTypes[0] <!UNRESOLVED_REFERENCE!>+=<!> 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() {
<!NO_VALUE_FOR_PARAMETER!>++MismatchingArities1[0]<!>
<!NO_VALUE_FOR_PARAMETER!>MismatchingArities1[0]++<!>
MismatchingArities1[0] <!UNRESOLVED_REFERENCE!>+=<!> 1
++<!NO_VALUE_FOR_PARAMETER!>MismatchingArities2[0]<!>
<!NO_VALUE_FOR_PARAMETER!>MismatchingArities2[0]<!>++
<!NO_VALUE_FOR_PARAMETER!>MismatchingArities2[0]<!> += 1
}