[FIR] Handle varargs in overloaded indexed access operator.

This commit is contained in:
Mark Punzalan
2020-09-22 23:16:46 -07:00
committed by teamcityserver
parent c471a7735e
commit f6ce2d893c
14 changed files with 94 additions and 11 deletions
@@ -0,0 +1,29 @@
object A {
var x = 0
var gets = 0
var sets = 0
operator fun get(vararg va: Int): Int {
for (i in va) {
gets += i
}
return x
}
operator fun set(vararg va: Int, value: Int) {
for (i in va) {
sets += i
}
x = value
}
}
fun box(): String {
A.x = 0
val xx = A[1, 2, 3]++
if (xx != 0) return "Failed xx: $xx"
if (A.x != 1) return "Failed A.x: ${A.x}"
if (A.gets != 6) return "Failed A.gets: ${A.gets}"
if (A.sets != 6) return "Failed A.sets: ${A.sets}"
return "OK"
}
@@ -28,8 +28,8 @@ fun test() {
B[0] = 2.72
B[0] = true
<!INAPPLICABLE_CANDIDATE!>D[0] = ""<!>
<!INAPPLICABLE_CANDIDATE!>D[0] = 2.72<!>
D[0] = ""
D[0] = 2.72
<!INAPPLICABLE_CANDIDATE!>Z[0] = ""<!>
}
+10 -5
View File
@@ -26,8 +26,13 @@ FILE fqName:<root> fileName:/kt28456a.kt
FUN name:testSimpleAssignment visibility:public modality:FINAL <> (a:<root>.A) returnType:kotlin.Unit
VALUE_PARAMETER name:a index:0 type:<root>.A
BLOCK_BODY
ERROR_CALL 'Unresolved reference: <Inapplicable(INAPPLICABLE_ARGUMENTS_MAPPING_ERROR): /set>#' type=kotlin.Unit
CONST Int type=kotlin.Int value=1
CONST Int type=kotlin.Int value=2
CONST Int type=kotlin.Int value=3
CONST Int type=kotlin.Int value=0
BLOCK type=kotlin.Unit origin=ARGUMENTS_REORDERING_FOR_CALL
VAR IR_TEMPORARY_VARIABLE name:tmp_0 type:kotlin.IntArray [val]
VARARG type=kotlin.IntArray varargElementType=kotlin.Int
CONST Int type=kotlin.Int value=1
CONST Int type=kotlin.Int value=2
CONST Int type=kotlin.Int value=3
CALL 'public final fun set (vararg i: kotlin.Int, v: kotlin.Int): kotlin.Unit [operator] declared in <root>' type=kotlin.Unit origin=null
$receiver: GET_VAR 'a: <root>.A declared in <root>.testSimpleAssignment' type=<root>.A origin=null
i: GET_VAR 'val tmp_0: kotlin.IntArray [val] declared in <root>.testSimpleAssignment' type=kotlin.IntArray origin=null
v: CONST Int type=kotlin.Int value=0