From eddef7527edcc97c0a0b4fb10aaf92ebc9aa9316 Mon Sep 17 00:00:00 2001 From: Anders Fugmann Date: Tue, 7 Jul 2026 15:14:50 +0200 Subject: [PATCH] kotlin tests: synchronise test inputs between test-kotlin1 and test-kotlin2 - Port ministdlib from test-kotlin1 to test-kotlin2. The ministdlib test exercises a minimal Kotlin standard library written from scratch. Its options file is updated to include -language-version 2.0 so the test runs in K2 mode when the K2 compiler is active. - Port nested_types from test-kotlin2 to test-kotlin1. The nested_types test exercises type-alias and inner-type queries. Expected output is identical in K1 and K2 modes so no expected-file changes are needed. - Add test-kotlin2/options with codeql-extractor-kotlin-options: -language-version 2.0. The CodeQL CLI adds -language-version 1.9 by default in legacy test extraction mode. Without this override the K2 test suite would run in K1 mode, defeating the purpose of the split. Both ministdlib and nested_types produce byte-identical expected output across K1 (2.3.20, -language-version 1.9) and K2 (2.4.0, default K2). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../library-tests/nested_types/test.kt | 16 +++++++ .../library-tests/nested_types/types.expected | 13 +++++ .../library-tests/nested_types/types.ql | 7 +++ .../library-tests/ministdlib/MiniStdLib.kt | 47 +++++++++++++++++++ .../library-tests/ministdlib/MyClass.kt | 1 + .../library-tests/ministdlib/classes.expected | 7 +++ .../library-tests/ministdlib/classes.ql | 4 ++ .../library-tests/ministdlib/options | 1 + java/ql/test-kotlin2/options | 1 + 9 files changed, 97 insertions(+) create mode 100644 java/ql/test-kotlin1/library-tests/nested_types/test.kt create mode 100644 java/ql/test-kotlin1/library-tests/nested_types/types.expected create mode 100644 java/ql/test-kotlin1/library-tests/nested_types/types.ql create mode 100644 java/ql/test-kotlin2/library-tests/ministdlib/MiniStdLib.kt create mode 100644 java/ql/test-kotlin2/library-tests/ministdlib/MyClass.kt create mode 100644 java/ql/test-kotlin2/library-tests/ministdlib/classes.expected create mode 100644 java/ql/test-kotlin2/library-tests/ministdlib/classes.ql create mode 100644 java/ql/test-kotlin2/library-tests/ministdlib/options create mode 100644 java/ql/test-kotlin2/options diff --git a/java/ql/test-kotlin1/library-tests/nested_types/test.kt b/java/ql/test-kotlin1/library-tests/nested_types/test.kt new file mode 100644 index 00000000000..7d5e2280b92 --- /dev/null +++ b/java/ql/test-kotlin1/library-tests/nested_types/test.kt @@ -0,0 +1,16 @@ + +import java.util.Stack; + +// Diagnostic Matches: %Making use of Stack a raw type to avoid infinite recursion% + +class MyType + +fun foo1(x: List>>>) { } + +fun foo2(x: Stack>>>) { } + +class MkT { } + +fun foo3(x: MkT>>>) { } + + diff --git a/java/ql/test-kotlin1/library-tests/nested_types/types.expected b/java/ql/test-kotlin1/library-tests/nested_types/types.expected new file mode 100644 index 00000000000..ec2e407b8b7 --- /dev/null +++ b/java/ql/test-kotlin1/library-tests/nested_types/types.expected @@ -0,0 +1,13 @@ +| file:///!unknown-binary-location/MkT.class:0:0:0:0 | MkT>>> | +| file:///!unknown-binary-location/MkT.class:0:0:0:0 | MkT>> | +| file:///!unknown-binary-location/MkT.class:0:0:0:0 | MkT> | +| file:///!unknown-binary-location/MkT.class:0:0:0:0 | MkT | +| file:///modules/java.base/java/util/List.class:0:0:0:0 | List>>> | +| file:///modules/java.base/java/util/List.class:0:0:0:0 | List>> | +| file:///modules/java.base/java/util/List.class:0:0:0:0 | List> | +| file:///modules/java.base/java/util/List.class:0:0:0:0 | List | +| file:///modules/java.base/java/util/List.class:0:0:0:0 | List> | +| file:///modules/java.base/java/util/Stack.class:0:0:0:0 | Stack | +| file:///modules/java.base/java/util/Stack.class:0:0:0:0 | Stack> | +| file:///modules/java.base/java/util/Stack.class:0:0:0:0 | Stack>> | +| file:///modules/java.base/java/util/Stack.class:0:0:0:0 | Stack>>> | diff --git a/java/ql/test-kotlin1/library-tests/nested_types/types.ql b/java/ql/test-kotlin1/library-tests/nested_types/types.ql new file mode 100644 index 00000000000..3499ae037c7 --- /dev/null +++ b/java/ql/test-kotlin1/library-tests/nested_types/types.ql @@ -0,0 +1,7 @@ +import java + +from Type t +where + t.getName().matches("%MyType%") and + t.getName().matches(["List<%", "Stack<%", "MkT<%"]) +select t diff --git a/java/ql/test-kotlin2/library-tests/ministdlib/MiniStdLib.kt b/java/ql/test-kotlin2/library-tests/ministdlib/MiniStdLib.kt new file mode 100644 index 00000000000..1aaba910fa2 --- /dev/null +++ b/java/ql/test-kotlin2/library-tests/ministdlib/MiniStdLib.kt @@ -0,0 +1,47 @@ +package kotlin + +/* +This is a mini standard library replacement, to make it easy to write +very small tests that create very small databases. + +If you define a class, then you will need to also define any members that +compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/descriptors/IrBuiltInsOverDescriptors.kt +expects (e.g. with findFunctions(...).first) to exist. +*/ + +public open class Any { + fun toString(): String { return this.toString() } + open operator fun equals(other: Any?): Boolean { return this.equals(other) } +} + +public class String { + operator fun plus(other: Any?): String { return this.plus(other) } +} + +public class Boolean { + operator fun not(): Boolean { return this.not() } +} + +public class Int { + operator fun plus(other: Int): Int { return this.plus(other) } + operator fun times(other: Int): Int { return this.times(other) } + infix fun xor(other: Int): Int { return this.xor(other) } + infix fun and(other: Int): Int { return this.and(other) } +} + +public object Unit { +} + +// Diagnostic Matches: % Can't find java.lang.Boolean +// Diagnostic Matches: % Can't find java.lang.Byte +// Diagnostic Matches: % Can't find java.lang.Character +// Diagnostic Matches: % Can't find java.lang.Double +// Diagnostic Matches: % Can't find java.lang.Float +// Diagnostic Matches: % Can't find java.lang.Integer +// Diagnostic Matches: % Can't find java.lang.Long +// Diagnostic Matches: % Can't find java.lang.Short +// Diagnostic Matches: % Can't find java.lang.Void +// Diagnostic Matches: % Can't find kotlin.UByte +// Diagnostic Matches: % Can't find kotlin.UInt +// Diagnostic Matches: % Can't find kotlin.ULong +// Diagnostic Matches: % Can't find kotlin.UShort diff --git a/java/ql/test-kotlin2/library-tests/ministdlib/MyClass.kt b/java/ql/test-kotlin2/library-tests/ministdlib/MyClass.kt new file mode 100644 index 00000000000..eaa7e450bbb --- /dev/null +++ b/java/ql/test-kotlin2/library-tests/ministdlib/MyClass.kt @@ -0,0 +1 @@ +class MyClass {} diff --git a/java/ql/test-kotlin2/library-tests/ministdlib/classes.expected b/java/ql/test-kotlin2/library-tests/ministdlib/classes.expected new file mode 100644 index 00000000000..36aaa6b629c --- /dev/null +++ b/java/ql/test-kotlin2/library-tests/ministdlib/classes.expected @@ -0,0 +1,7 @@ +| MiniStdLib.kt:12:1:15:1 | Any | +| MiniStdLib.kt:17:1:19:1 | String | +| MiniStdLib.kt:21:1:23:1 | Boolean | +| MiniStdLib.kt:25:1:30:1 | Int | +| MiniStdLib.kt:32:1:33:1 | Unit | +| MyClass.kt:1:1:1:16 | MyClass | +| file://:0:0:0:0 | FakeKotlinClass | diff --git a/java/ql/test-kotlin2/library-tests/ministdlib/classes.ql b/java/ql/test-kotlin2/library-tests/ministdlib/classes.ql new file mode 100644 index 00000000000..86c654ea986 --- /dev/null +++ b/java/ql/test-kotlin2/library-tests/ministdlib/classes.ql @@ -0,0 +1,4 @@ +import java + +from Class c +select c diff --git a/java/ql/test-kotlin2/library-tests/ministdlib/options b/java/ql/test-kotlin2/library-tests/ministdlib/options new file mode 100644 index 00000000000..6063ff96d81 --- /dev/null +++ b/java/ql/test-kotlin2/library-tests/ministdlib/options @@ -0,0 +1 @@ +codeql-extractor-kotlin-options: -no-jdk -no-reflect -no-stdlib -Xallow-kotlin-package -language-version 2.0 diff --git a/java/ql/test-kotlin2/options b/java/ql/test-kotlin2/options new file mode 100644 index 00000000000..3492bf52d99 --- /dev/null +++ b/java/ql/test-kotlin2/options @@ -0,0 +1 @@ +codeql-extractor-kotlin-options: -language-version 2.0