Skip to content

Commit 5f841f7

Browse files
authored
Merge pull request #10291 from tamasvajk/kotlin-fix-array-set
Kotlin: Fix array `set` operator extraction
2 parents 604af4f + 6f7f760 commit 5f841f7

File tree

3 files changed

+68
-19
lines changed

3 files changed

+68
-19
lines changed

java/kotlin-extractor/src/main/kotlin/KotlinFileExtractor.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2208,7 +2208,7 @@ open class KotlinFileExtractor(
22082208
tw.writeExprsKotlinType(id, type.kotlinResult.id)
22092209
binopDisp(id)
22102210
}
2211-
isFunction(target, "kotlin", "(some array type)", { isArrayType(it) }, "set") && c.origin == IrStatementOrigin.EQ -> {
2211+
isFunction(target, "kotlin", "(some array type)", { isArrayType(it) }, "set") && c.origin == IrStatementOrigin.EQ && c.dispatchReceiver != null -> {
22122212
val array = c.dispatchReceiver
22132213
val arrayIdx = c.getValueArgument(0)
22142214
val assignedValue = c.getValueArgument(1)

java/ql/test/kotlin/library-tests/operator-overloads/PrintAst.expected

Lines changed: 62 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,30 +30,74 @@ test.kt:
3030
# 4| -1: [VarAccess] mt
3131
# 4| 0: [IntegerLiteral] 1
3232
# 4| 1: [IntegerLiteral] 2
33-
# 7| 2: [ExtensionMethod] get
34-
# 7| 3: [TypeAccess] String
33+
# 6| 3: [ExprStmt] <Expr>;
34+
# 6| 0: [ImplicitCoercionToUnitExpr] <implicit coercion to unit>
35+
# 6| 0: [TypeAccess] Unit
36+
# 6| 1: [MethodAccess] set(...)
37+
# 6| -1: [TypeAccess] TestKt
38+
# 6| 0: [VarAccess] arr
39+
# 6| 1: [IntegerLiteral] 1
40+
# 6| 2: [IntegerLiteral] 2
41+
# 6| 3: [IntegerLiteral] 3
42+
# 7| 4: [ExprStmt] <Expr>;
43+
# 7| 0: [ImplicitCoercionToUnitExpr] <implicit coercion to unit>
44+
# 7| 0: [TypeAccess] Unit
45+
# 7| 1: [MethodAccess] set(...)
46+
# 7| -1: [TypeAccess] TestKt
47+
# 7| 0: [VarAccess] arr
48+
# 7| 1: [IntegerLiteral] 1
49+
# 7| 2: [ClassInstanceExpr] new C(...)
50+
# 7| -3: [TypeAccess] C
51+
# 10| 2: [ExtensionMethod] get
52+
# 10| 3: [TypeAccess] String
3553
#-----| 4: (Parameters)
36-
# 7| 0: [Parameter] <this>
37-
# 7| 0: [TypeAccess] byte[]
38-
# 7| 1: [Parameter] i
39-
# 7| 0: [TypeAccess] int
40-
# 7| 2: [Parameter] j
41-
# 7| 0: [TypeAccess] int
42-
# 7| 5: [BlockStmt] { ... }
43-
# 7| 0: [ReturnStmt] return ...
44-
# 7| 0: [StringLiteral]
45-
# 10| 2: [Class] C
46-
# 10| 1: [Constructor] C
54+
# 10| 0: [Parameter] <this>
55+
# 10| 0: [TypeAccess] byte[]
56+
# 10| 1: [Parameter] i
57+
# 10| 0: [TypeAccess] int
58+
# 10| 2: [Parameter] j
59+
# 10| 0: [TypeAccess] int
4760
# 10| 5: [BlockStmt] { ... }
48-
# 10| 0: [SuperConstructorInvocationStmt] super(...)
49-
# 10| 1: [BlockStmt] { ... }
50-
# 11| 2: [Method] get
61+
# 10| 0: [ReturnStmt] return ...
62+
# 10| 0: [StringLiteral]
63+
# 11| 3: [ExtensionMethod] set
5164
# 11| 3: [TypeAccess] String
5265
#-----| 4: (Parameters)
53-
# 11| 0: [Parameter] i
66+
# 11| 0: [Parameter] <this>
67+
# 11| 0: [TypeAccess] byte[]
68+
# 11| 1: [Parameter] i
5469
# 11| 0: [TypeAccess] int
55-
# 11| 1: [Parameter] j
70+
# 11| 2: [Parameter] j
71+
# 11| 0: [TypeAccess] int
72+
# 11| 3: [Parameter] k
5673
# 11| 0: [TypeAccess] int
5774
# 11| 5: [BlockStmt] { ... }
5875
# 11| 0: [ReturnStmt] return ...
5976
# 11| 0: [StringLiteral]
77+
# 12| 4: [ExtensionMethod] set
78+
# 12| 3: [TypeAccess] String
79+
#-----| 4: (Parameters)
80+
# 12| 0: [Parameter] <this>
81+
# 12| 0: [TypeAccess] byte[]
82+
# 12| 1: [Parameter] i
83+
# 12| 0: [TypeAccess] int
84+
# 12| 2: [Parameter] c
85+
# 12| 0: [TypeAccess] C
86+
# 12| 5: [BlockStmt] { ... }
87+
# 12| 0: [ReturnStmt] return ...
88+
# 12| 0: [StringLiteral]
89+
# 15| 2: [Class] C
90+
# 15| 1: [Constructor] C
91+
# 15| 5: [BlockStmt] { ... }
92+
# 15| 0: [SuperConstructorInvocationStmt] super(...)
93+
# 15| 1: [BlockStmt] { ... }
94+
# 16| 2: [Method] get
95+
# 16| 3: [TypeAccess] String
96+
#-----| 4: (Parameters)
97+
# 16| 0: [Parameter] i
98+
# 16| 0: [TypeAccess] int
99+
# 16| 1: [Parameter] j
100+
# 16| 0: [TypeAccess] int
101+
# 16| 5: [BlockStmt] { ... }
102+
# 16| 0: [ReturnStmt] return ...
103+
# 16| 0: [StringLiteral]

java/ql/test/kotlin/library-tests/operator-overloads/test.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@ fun fn(arr: ByteArray, mt: C) {
22
arr[1]
33
arr[1, 2]
44
mt[1, 2]
5+
6+
arr[1, 2] = 3
7+
arr[1] = C()
58
}
69

710
public operator fun ByteArray.get(i: Int, j: Int) = ""
11+
public operator fun ByteArray.set(i: Int, j: Int, k: Int) = ""
12+
public operator fun ByteArray.set(i: Int, c: C) = ""
813

914

1015
public class C {

0 commit comments

Comments
 (0)