From 69e226b1997209dce1235a61344ce553e8763c73 Mon Sep 17 00:00:00 2001 From: Anders Fugmann Date: Tue, 7 Jul 2026 15:33:29 +0200 Subject: [PATCH] kotlin tests: sync dataflow/foreach test inputs and K2 expected output Copy K1's richer C2.kt (which includes test2, test3 and l.get(0) in test) into test-kotlin2. K2 in -language 2.0 mode already tracks dataflow through array.set() and indirect wrapper calls, so the additional tests produce results identical to K1. The expected files for test-kotlin1 and test-kotlin2 are now byte-identical for this test. Verified: - test-kotlin1 (kotlinc 2.3.20 / -language 1.9): all tests pass - test-kotlin2 (kotlinc 2.4.0 / -language 2.0): all tests pass Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../library-tests/dataflow/foreach/C2.kt | 22 +++++++++++++++++++ .../dataflow/foreach/test.expected | 11 ++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/java/ql/test-kotlin2/library-tests/dataflow/foreach/C2.kt b/java/ql/test-kotlin2/library-tests/dataflow/foreach/C2.kt index 7a98abaa110..794ab819d3d 100644 --- a/java/ql/test-kotlin2/library-tests/dataflow/foreach/C2.kt +++ b/java/ql/test-kotlin2/library-tests/dataflow/foreach/C2.kt @@ -8,6 +8,7 @@ class C2 { val l = arrayOf(taint("a"), "") sink(l) sink(l[0]) + sink(l.get(0)) for (i in l.indices) { sink(l[i]) } @@ -15,4 +16,25 @@ class C2 { sink(s) } } + + fun test2() { + val l1 = arrayOf("") + val l2 = arrayOf("") + l1[0] = taint("a") + l2.set(0, taint("a")) + sink(l1[0]) + sink(l2[0]) + sink(l1.get(0)) + sink(l2.get(0)) + } + + fun setWrapper(l: Array, v: String) { + l.set(0, v) + } + fun test3() { + val l = arrayOf("") + setWrapper(l, taint("a")) + sink(l[0]) + sink(l.get(0)) + } } diff --git a/java/ql/test-kotlin2/library-tests/dataflow/foreach/test.expected b/java/ql/test-kotlin2/library-tests/dataflow/foreach/test.expected index 53af5d4a0c0..08b696743a4 100644 --- a/java/ql/test-kotlin2/library-tests/dataflow/foreach/test.expected +++ b/java/ql/test-kotlin2/library-tests/dataflow/foreach/test.expected @@ -4,5 +4,12 @@ | C1.java:10:44:10:46 | "a" | C1.java:19:20:19:20 | s | | C2.kt:8:31:8:33 | "a" | C2.kt:9:14:9:14 | l | | C2.kt:8:31:8:33 | "a" | C2.kt:10:14:10:17 | ...[...] | -| C2.kt:8:31:8:33 | "a" | C2.kt:12:18:12:21 | ...[...] | -| C2.kt:8:31:8:33 | "a" | C2.kt:15:18:15:18 | s | +| C2.kt:8:31:8:33 | "a" | C2.kt:11:14:11:21 | get(...) | +| C2.kt:8:31:8:33 | "a" | C2.kt:13:18:13:21 | ...[...] | +| C2.kt:8:31:8:33 | "a" | C2.kt:16:18:16:18 | s | +| C2.kt:23:23:23:25 | "a" | C2.kt:25:14:25:18 | ...[...] | +| C2.kt:23:23:23:25 | "a" | C2.kt:27:14:27:22 | get(...) | +| C2.kt:24:25:24:27 | "a" | C2.kt:26:14:26:18 | ...[...] | +| C2.kt:24:25:24:27 | "a" | C2.kt:28:14:28:22 | get(...) | +| C2.kt:36:29:36:31 | "a" | C2.kt:37:14:37:17 | ...[...] | +| C2.kt:36:29:36:31 | "a" | C2.kt:38:14:38:21 | get(...) |