Files
codeql/java/ql/test-kotlin2/library-tests/dataflow/foreach/C2.kt
Anders Fugmann 1778b15936 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>
2026-07-10 19:58:27 +02:00

41 lines
768 B
Kotlin

class C2 {
fun taint(t: String): String {
return t
}
fun sink(a: Any?) {}
fun test() {
val l = arrayOf(taint("a"), "")
sink(l)
sink(l[0])
sink(l.get(0))
for (i in l.indices) {
sink(l[i])
}
for (s in l) {
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<String>, v: String) {
l.set(0, v)
}
fun test3() {
val l = arrayOf("")
setWrapper(l, taint("a"))
sink(l[0])
sink(l.get(0))
}
}