Skip to content

Commit 0f9b6d4

Browse files
committed
Kotlin: Add test cases for operators being called by name
1 parent ef8ec08 commit 0f9b6d4

File tree

4 files changed

+87
-0
lines changed

4 files changed

+87
-0
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
test.kt:
2+
# 0| [CompilationUnit] test
3+
# 0| 1: [Class] TestKt
4+
# 1| 1: [Method] test
5+
# 1| 3: [TypeAccess] int
6+
#-----| 4: (Parameters)
7+
# 1| 0: [Parameter] m
8+
# 1| 0: [TypeAccess] Map<Integer,Integer>
9+
# 1| 0: [TypeAccess] Integer
10+
# 1| 1: [TypeAccess] Integer
11+
# 1| 5: [BlockStmt] { ... }
12+
# 1| 0: [ReturnStmt] return ...
13+
# 1| 0: [MethodAccess] getOrDefault(...)
14+
# 1| -1: [VarAccess] m
15+
# 1| 0: [IntegerLiteral] 1
16+
# 1| 1: [IntegerLiteral] 2
17+
# 3| 2: [Method] test2
18+
# 3| 3: [TypeAccess] int
19+
#-----| 4: (Parameters)
20+
# 3| 0: [Parameter] s
21+
# 3| 0: [TypeAccess] String
22+
# 3| 5: [BlockStmt] { ... }
23+
# 3| 0: [ReturnStmt] return ...
24+
# 3| 0: [MethodAccess] length(...)
25+
# 3| -1: [VarAccess] s
26+
# 5| 3: [Method] remove
27+
# 5| 3: [TypeAccess] Unit
28+
#-----| 4: (Parameters)
29+
# 5| 0: [Parameter] l
30+
# 5| 0: [TypeAccess] List<Integer>
31+
# 5| 0: [TypeAccess] Integer
32+
# 5| 5: [BlockStmt] { ... }
33+
# 6| 0: [ExprStmt] <Expr>;
34+
# 6| 0: [ImplicitCoercionToUnitExpr] <implicit coercion to unit>
35+
# 6| 0: [TypeAccess] Unit
36+
# 6| 1: [MethodAccess] remove(...)
37+
# 6| -1: [VarAccess] l
38+
# 6| 0: [IntegerLiteral] 5
39+
# 9| 4: [Method] fn1
40+
# 9| 3: [TypeAccess] String
41+
#-----| 4: (Parameters)
42+
# 9| 0: [Parameter] s
43+
# 9| 0: [TypeAccess] String
44+
# 9| 5: [BlockStmt] { ... }
45+
# 9| 0: [ReturnStmt] return ...
46+
# 9| 0: [MethodAccess] plus(...)
47+
# 9| -1: [VarAccess] s
48+
# 9| 0: [StringLiteral]
49+
# 10| 5: [Method] fn2
50+
# 10| 3: [TypeAccess] String
51+
#-----| 4: (Parameters)
52+
# 10| 0: [Parameter] s
53+
# 10| 0: [TypeAccess] String
54+
# 10| 5: [BlockStmt] { ... }
55+
# 10| 0: [ReturnStmt] return ...
56+
# 10| 0: [AddExpr] ... + ...
57+
# 10| 0: [VarAccess] s
58+
# 10| 1: [StringLiteral]
59+
# 12| 6: [Method] fn1
60+
# 12| 3: [TypeAccess] int
61+
#-----| 4: (Parameters)
62+
# 12| 0: [Parameter] i
63+
# 12| 0: [TypeAccess] int
64+
# 12| 5: [BlockStmt] { ... }
65+
# 12| 0: [ReturnStmt] return ...
66+
# 12| 0: [MethodAccess] minus(...)
67+
# 12| -1: [VarAccess] i
68+
# 12| 0: [IntegerLiteral] 10
69+
# 13| 7: [Method] fn2
70+
# 13| 3: [TypeAccess] int
71+
#-----| 4: (Parameters)
72+
# 13| 0: [Parameter] i
73+
# 13| 0: [TypeAccess] int
74+
# 13| 5: [BlockStmt] { ... }
75+
# 13| 0: [ReturnStmt] return ...
76+
# 13| 0: [SubExpr] ... - ...
77+
# 13| 0: [VarAccess] i
78+
# 13| 1: [IntegerLiteral] 10
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
semmle/code/java/PrintAst.ql
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
diagnostics
2+
| file://:0:0:0:0 | Couldn't find a Java equivalent function to kotlin.String.plus in java.lang.String |
23
#select
34
| Integer |
45
| Object |
6+
| int |

java/ql/test/kotlin/library-tests/java-map-methods/test.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,9 @@ fun test2(s: String) = s.length
55
fun remove(l: MutableList<Int>) {
66
l.remove(5)
77
}
8+
9+
fun fn1(s: String) = s.plus(other = "")
10+
fun fn2(s: String) = s + ""
11+
12+
fun fn1(i: Int) = i.minus(10)
13+
fun fn2(i: Int) = i - 10

0 commit comments

Comments
 (0)