Skip to content

Commit 608f99b

Browse files
committed
Kotlin: Add test case for various array set operator overloads
1 parent 48761b8 commit 608f99b

File tree

3 files changed

+57
-18
lines changed

3 files changed

+57
-18
lines changed

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

Lines changed: 50 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,30 +30,62 @@ 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+
# 7| 4: [ExprStmt] <Expr>;
37+
# 7| 0: [ImplicitCoercionToUnitExpr] <implicit coercion to unit>
38+
# 7| 0: [TypeAccess] Unit
39+
# 10| 2: [ExtensionMethod] get
40+
# 10| 3: [TypeAccess] String
3541
#-----| 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
42+
# 10| 0: [Parameter] <this>
43+
# 10| 0: [TypeAccess] byte[]
44+
# 10| 1: [Parameter] i
45+
# 10| 0: [TypeAccess] int
46+
# 10| 2: [Parameter] j
47+
# 10| 0: [TypeAccess] int
4748
# 10| 5: [BlockStmt] { ... }
48-
# 10| 0: [SuperConstructorInvocationStmt] super(...)
49-
# 10| 1: [BlockStmt] { ... }
50-
# 11| 2: [Method] get
49+
# 10| 0: [ReturnStmt] return ...
50+
# 10| 0: [StringLiteral]
51+
# 11| 3: [ExtensionMethod] set
5152
# 11| 3: [TypeAccess] String
5253
#-----| 4: (Parameters)
53-
# 11| 0: [Parameter] i
54+
# 11| 0: [Parameter] <this>
55+
# 11| 0: [TypeAccess] byte[]
56+
# 11| 1: [Parameter] i
5457
# 11| 0: [TypeAccess] int
55-
# 11| 1: [Parameter] j
58+
# 11| 2: [Parameter] j
59+
# 11| 0: [TypeAccess] int
60+
# 11| 3: [Parameter] k
5661
# 11| 0: [TypeAccess] int
5762
# 11| 5: [BlockStmt] { ... }
5863
# 11| 0: [ReturnStmt] return ...
5964
# 11| 0: [StringLiteral]
65+
# 12| 4: [ExtensionMethod] set
66+
# 12| 3: [TypeAccess] String
67+
#-----| 4: (Parameters)
68+
# 12| 0: [Parameter] <this>
69+
# 12| 0: [TypeAccess] byte[]
70+
# 12| 1: [Parameter] i
71+
# 12| 0: [TypeAccess] int
72+
# 12| 2: [Parameter] c
73+
# 12| 0: [TypeAccess] C
74+
# 12| 5: [BlockStmt] { ... }
75+
# 12| 0: [ReturnStmt] return ...
76+
# 12| 0: [StringLiteral]
77+
# 15| 2: [Class] C
78+
# 15| 1: [Constructor] C
79+
# 15| 5: [BlockStmt] { ... }
80+
# 15| 0: [SuperConstructorInvocationStmt] super(...)
81+
# 15| 1: [BlockStmt] { ... }
82+
# 16| 2: [Method] get
83+
# 16| 3: [TypeAccess] String
84+
#-----| 4: (Parameters)
85+
# 16| 0: [Parameter] i
86+
# 16| 0: [TypeAccess] int
87+
# 16| 1: [Parameter] j
88+
# 16| 0: [TypeAccess] int
89+
# 16| 5: [BlockStmt] { ... }
90+
# 16| 0: [ReturnStmt] return ...
91+
# 16| 0: [StringLiteral]
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
| test.kt:6:5:6:13 | Unexpected Array.set function signature |
2+
| test.kt:7:5:7:10 | Unexpected Array.set function signature |

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)