Skip to content

Commit 6576f19

Browse files
authored
Merge pull request #10255 from tamasvajk/kotlin-array-get-fix
Kotlin: Fix array indexer extraction
2 parents 00c5509 + a5415c9 commit 6576f19

File tree

6 files changed

+79
-1
lines changed

6 files changed

+79
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2185,7 +2185,7 @@ open class KotlinFileExtractor(
21852185
}
21862186
}
21872187
}
2188-
isFunction(target, "kotlin", "(some array type)", { isArrayType(it) }, "get") && c.origin == IrStatementOrigin.GET_ARRAY_ELEMENT -> {
2188+
isFunction(target, "kotlin", "(some array type)", { isArrayType(it) }, "get") && c.origin == IrStatementOrigin.GET_ARRAY_ELEMENT && c.dispatchReceiver != null -> {
21892189
val id = tw.getFreshIdLabel<DbArrayaccess>()
21902190
val type = useType(c.type)
21912191
tw.writeExprs_arrayaccess(id, type.javaResult.id, parent, idx)
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
test.kt:
2+
# 0| [CompilationUnit] test
3+
# 0| 1: [Class] TestKt
4+
# 1| 1: [Method] fn
5+
# 1| 3: [TypeAccess] Unit
6+
#-----| 4: (Parameters)
7+
# 1| 0: [Parameter] arr
8+
# 1| 0: [TypeAccess] byte[]
9+
# 1| 1: [Parameter] mt
10+
# 1| 0: [TypeAccess] C
11+
# 1| 5: [BlockStmt] { ... }
12+
# 2| 0: [ExprStmt] <Expr>;
13+
# 2| 0: [ImplicitCoercionToUnitExpr] <implicit coercion to unit>
14+
# 2| 0: [TypeAccess] Unit
15+
# 2| 1: [ArrayAccess] ...[...]
16+
# 2| 0: [VarAccess] arr
17+
# 2| 1: [IntegerLiteral] 1
18+
# 3| 1: [ExprStmt] <Expr>;
19+
# 3| 0: [ImplicitCoercionToUnitExpr] <implicit coercion to unit>
20+
# 3| 0: [TypeAccess] Unit
21+
# 3| 1: [MethodAccess] get(...)
22+
# 3| -1: [TypeAccess] TestKt
23+
# 3| 0: [VarAccess] arr
24+
# 3| 1: [IntegerLiteral] 1
25+
# 3| 2: [IntegerLiteral] 2
26+
# 4| 2: [ExprStmt] <Expr>;
27+
# 4| 0: [ImplicitCoercionToUnitExpr] <implicit coercion to unit>
28+
# 4| 0: [TypeAccess] Unit
29+
# 4| 1: [MethodAccess] get(...)
30+
# 4| -1: [VarAccess] mt
31+
# 4| 0: [IntegerLiteral] 1
32+
# 4| 1: [IntegerLiteral] 2
33+
# 7| 2: [ExtensionMethod] get
34+
# 7| 3: [TypeAccess] String
35+
#-----| 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
47+
# 10| 5: [BlockStmt] { ... }
48+
# 10| 0: [SuperConstructorInvocationStmt] super(...)
49+
# 10| 1: [BlockStmt] { ... }
50+
# 11| 2: [Method] get
51+
# 11| 3: [TypeAccess] String
52+
#-----| 4: (Parameters)
53+
# 11| 0: [Parameter] i
54+
# 11| 0: [TypeAccess] int
55+
# 11| 1: [Parameter] j
56+
# 11| 0: [TypeAccess] int
57+
# 11| 5: [BlockStmt] { ... }
58+
# 11| 0: [ReturnStmt] return ...
59+
# 11| 0: [StringLiteral]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
semmle/code/java/PrintAst.ql

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

Whitespace-only changes.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
fun fn(arr: ByteArray, mt: C) {
2+
arr[1]
3+
arr[1, 2]
4+
mt[1, 2]
5+
}
6+
7+
public operator fun ByteArray.get(i: Int, j: Int) = ""
8+
9+
10+
public class C {
11+
public operator fun get(i: Int, j: Int) = ""
12+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import java
2+
import java
3+
import semmle.code.java.Diagnostics
4+
5+
from Diagnostic d
6+
select d

0 commit comments

Comments
 (0)