Skip to content

Commit cb3c53d

Browse files
committed
Kotlin: Add test case for unexpected vararg extraction error
1 parent 5f841f7 commit cb3c53d

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

java/ql/test/kotlin/library-tests/vararg/args.expected

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
1+
diag
2+
| test.kt:55:15:55:35 | Unexpected IrVararg |
13
varargsParams
24
| test.kt:8:15:8:28 | xs | file://:0:0:0:0 | int[] |
35
| test.kt:12:26:12:39 | xs | file://:0:0:0:0 | int[] |
46
| test.kt:20:24:20:37 | xs | file://:0:0:0:0 | int[] |
57
| test.kt:24:50:24:63 | xs | file://:0:0:0:0 | int[] |
68
| test.kt:28:37:28:50 | xs | file://:0:0:0:0 | int[] |
9+
| test.kt:50:5:50:31 | s | file://:0:0:0:0 | String[] |
710
explicitVarargsArguments
811
| test.kt:12:50:12:51 | xs | test.kt:12:44:12:52 | this(...) |
912
| test.kt:38:25:38:29 | array | test.kt:38:5:38:30 | funWithOnlyVarArgs(...) |
1013
| test.kt:39:41:39:45 | array | test.kt:39:5:39:46 | funWithArgsAndVarArgs(...) |
1114
| test.kt:40:34:40:38 | array | test.kt:40:5:40:49 | funWithMiddleVarArgs(...) |
1215
| test.kt:44:27:44:31 | array | test.kt:44:5:44:32 | new HasVarargConstructor(...) |
1316
| test.kt:45:34:45:38 | array | test.kt:45:5:45:39 | new HasVarargConstructor(...) |
17+
| test.kt:55:15:55:35 | tmp0_s | test.kt:55:13:55:43 | new X(...) |
1418
implicitVarargsArguments
1519
| intList.kt:3:21:3:22 | 10 | intList.kt:3:14:3:31 | listOf(...) | 0 |
1620
| intList.kt:3:25:3:26 | 11 | intList.kt:3:14:3:31 | listOf(...) | 1 |
@@ -78,3 +82,5 @@ implicitVarargsArguments
7882
| test.kt:44:5:44:32 | new HasVarargConstructor(...) | 0 | test.kt:44:27:44:31 | array |
7983
| test.kt:45:5:45:39 | new HasVarargConstructor(...) | 0 | test.kt:45:27:45:29 | foo |
8084
| test.kt:45:5:45:39 | new HasVarargConstructor(...) | 1 | test.kt:45:34:45:38 | array |
85+
| test.kt:55:13:55:43 | new X(...) | 0 | test.kt:55:42:55:42 | 1 |
86+
| test.kt:55:13:55:43 | new X(...) | 1 | test.kt:55:15:55:35 | tmp0_s |

java/ql/test/kotlin/library-tests/vararg/args.ql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
import java
2+
import semmle.code.java.Diagnostics
3+
4+
query predicate diag(Diagnostic d) {
5+
d.getMessage() = "Unexpected IrVararg"
6+
}
27

38
query predicate varargsParams(Parameter p, Type t) {
49
p.getCallable().fromSource() and

java/ql/test/kotlin/library-tests/vararg/test.kt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
fun sink(sunk: Int) {
3-
3+
44
}
55

66
open class HasVarargConstructor {
@@ -44,3 +44,13 @@ fun myFun() {
4444
HasVarargConstructor(*array)
4545
HasVarargConstructor("foo", *array)
4646
}
47+
48+
open class X(
49+
i: Int,
50+
public vararg val s: String
51+
) { }
52+
53+
fun fn(sl: List<String>) {
54+
// reordered args:
55+
val x = X(s = sl.toTypedArray(), i = 1)
56+
}

0 commit comments

Comments
 (0)