diff --git a/MODULE.bazel b/MODULE.bazel index 91c871445eb4..7bffb320d1eb 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -275,6 +275,7 @@ use_repo( "kotlin-compiler-2.3.0", "kotlin-compiler-2.3.20", "kotlin-compiler-2.4.0", + "kotlin-compiler-2.4.20-RC", "kotlin-compiler-embeddable-1.8.0", "kotlin-compiler-embeddable-1.9.0-Beta", "kotlin-compiler-embeddable-1.9.20-Beta", @@ -287,6 +288,7 @@ use_repo( "kotlin-compiler-embeddable-2.3.0", "kotlin-compiler-embeddable-2.3.20", "kotlin-compiler-embeddable-2.4.0", + "kotlin-compiler-embeddable-2.4.20-RC", "kotlin-stdlib-1.8.0", "kotlin-stdlib-1.9.0-Beta", "kotlin-stdlib-1.9.20-Beta", @@ -299,6 +301,7 @@ use_repo( "kotlin-stdlib-2.3.0", "kotlin-stdlib-2.3.20", "kotlin-stdlib-2.4.0", + "kotlin-stdlib-2.4.20-RC", ) go_sdk = use_extension("@rules_go//go:extensions.bzl", "go_sdk") diff --git a/docs/codeql/reusables/supported-versions-compilers.rst b/docs/codeql/reusables/supported-versions-compilers.rst index 8651fa91a269..e1a113092bb2 100644 --- a/docs/codeql/reusables/supported-versions-compilers.rst +++ b/docs/codeql/reusables/supported-versions-compilers.rst @@ -21,7 +21,7 @@ Java,"Java 7 to 26 [5]_","javac (OpenJDK and Oracle JDK), Eclipse compiler for Java (ECJ) [6]_",``.java`` - Kotlin,"Kotlin 1.8.0 to 2.4.1\ *x*","kotlinc",``.kt`` + Kotlin,"Kotlin 1.8.0 to 2.4.20-RC","kotlinc",``.kt`` JavaScript,ECMAScript 2022 or lower,Not applicable,"``.js``, ``.jsx``, ``.mjs``, ``.es``, ``.es6``, ``.htm``, ``.html``, ``.xhtm``, ``.xhtml``, ``.vue``, ``.hbs``, ``.ejs``, ``.njk``, ``.json``, ``.yaml``, ``.yml``, ``.raml``, ``.xml`` [7]_" Python [8]_,"2.7, 3.5, 3.6, 3.7, 3.8, 3.9, 3.10, 3.11, 3.12, 3.13, 3.14",Not applicable,``.py`` Ruby,"up to 3.3",Not applicable,"``.rb``, ``.erb``, ``.gemspec``, ``Gemfile``" diff --git a/java/kotlin-extractor/BUILD.bazel b/java/kotlin-extractor/BUILD.bazel index f33949f83914..fae93f6a2cc4 100644 --- a/java/kotlin-extractor/BUILD.bazel +++ b/java/kotlin-extractor/BUILD.bazel @@ -57,6 +57,10 @@ _compiler_plugin_registrar_service_source = "src/main/resources/META-INF/service _compiler_plugin_registrar_service_target = "META-INF/services/org.jetbrains.kotlin.compiler.plugin.CompilerPluginRegistrar" +_component_registrar_service_source = "src/main/resources/META-INF/services/org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar" + +_component_registrar_service_target = "META-INF/services/org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar" + py_binary( name = "generate_dbscheme", srcs = ["generate_dbscheme.py"], @@ -68,7 +72,10 @@ _resources = [ r[len("src/main/resources/"):], ) for r in glob(["src/main/resources/**"]) - if r != _compiler_plugin_registrar_service_source + if r not in ( + _compiler_plugin_registrar_service_source, + _component_registrar_service_source, + ) ] _compiler_plugin_registrar_service = ( @@ -76,6 +83,11 @@ _compiler_plugin_registrar_service = ( _compiler_plugin_registrar_service_target, ) +_component_registrar_service = ( + _component_registrar_service_source, + _component_registrar_service_target, +) + kt_javac_options( name = "javac-options", release = "8", @@ -93,7 +105,11 @@ kt_javac_options( "kotlin.RequiresOptIn", "org.jetbrains.kotlin.ir.symbols.%s" % ("IrSymbolInternals" if version_less(v, "2.0.0") else "UnsafeDuringIrConstructionAPI"), - ] + ([] if version_less(v, "2.2.20") else ["org.jetbrains.kotlin.DeprecatedForRemovalCompilerApi"]), + ] + ( + [] if version_less(v, "2.2.20") else ["org.jetbrains.kotlin.DeprecatedForRemovalCompilerApi"] + ) + ( + [] if version_less(v, "2.4.20") else ["org.jetbrains.kotlin.K1Deprecation"] + ), x_suppress_version_warnings = True, ), # * extractor.name is different for each version, so we need to put it in different output dirs @@ -103,6 +119,8 @@ kt_javac_options( name = "resources-%s" % v, srcs = [src for src, _ in _resources] + ( [_compiler_plugin_registrar_service[0]] if not version_less(v, "2.4.0") else [] + ) + ( + [_component_registrar_service[0]] if version_less(v, "2.4.20") else [] ), outs = [ "%s/com/github/codeql/extractor.name" % v, @@ -114,6 +132,11 @@ kt_javac_options( v, _compiler_plugin_registrar_service[1], )] if not version_less(v, "2.4.0") else [] + ) + ( + ["%s/%s" % ( + v, + _component_registrar_service[1], + )] if version_less(v, "2.4.20") else [] ), cmd = "\n".join([ "echo %s-%s > $(RULEDIR)/%s/com/github/codeql/extractor.name" % (_extractor_name_prefix, v, v), @@ -126,6 +149,12 @@ kt_javac_options( v, _compiler_plugin_registrar_service[1], )] if not version_less(v, "2.4.0") else [] + ) + ( + ["cp $(execpath %s) $(RULEDIR)/%s/%s" % ( + _component_registrar_service[0], + v, + _component_registrar_service[1], + )] if version_less(v, "2.4.20") else [] )), ), kt_jvm_library( diff --git a/java/kotlin-extractor/deps/kotlin-compiler-2.4.20-RC.jar b/java/kotlin-extractor/deps/kotlin-compiler-2.4.20-RC.jar new file mode 100644 index 000000000000..8e5a4c945250 --- /dev/null +++ b/java/kotlin-extractor/deps/kotlin-compiler-2.4.20-RC.jar @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5e2e10f209ef5a63ed70d04ab5c64a8cf346c323f356eb4241ce34ee03cf2e53 +size 60184229 diff --git a/java/kotlin-extractor/deps/kotlin-compiler-embeddable-2.4.20-RC.jar b/java/kotlin-extractor/deps/kotlin-compiler-embeddable-2.4.20-RC.jar new file mode 100644 index 000000000000..4a7601447f96 --- /dev/null +++ b/java/kotlin-extractor/deps/kotlin-compiler-embeddable-2.4.20-RC.jar @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fac41bf816409462e189b41b87c4a8dfb48b995b4d8d6271968d4f638ceab255 +size 58593000 diff --git a/java/kotlin-extractor/deps/kotlin-stdlib-2.4.20-RC.jar b/java/kotlin-extractor/deps/kotlin-stdlib-2.4.20-RC.jar new file mode 100644 index 000000000000..2fb1da42a55a --- /dev/null +++ b/java/kotlin-extractor/deps/kotlin-stdlib-2.4.20-RC.jar @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:540bee6d6310863014877cb4df8f087c256b22d0925955d1d20943d706bba524 +size 1853317 diff --git a/java/kotlin-extractor/dev/wrapper.py b/java/kotlin-extractor/dev/wrapper.py index 1b29de23f766..8c795418f67e 100755 --- a/java/kotlin-extractor/dev/wrapper.py +++ b/java/kotlin-extractor/dev/wrapper.py @@ -27,7 +27,7 @@ import io import os -DEFAULT_VERSION = "2.4.10" +DEFAULT_VERSION = "2.4.20-RC" def options(): diff --git a/java/kotlin-extractor/src/main/kotlin/KotlinFileExtractor.kt b/java/kotlin-extractor/src/main/kotlin/KotlinFileExtractor.kt index 0b975d9b829b..bef2b554d7ec 100644 --- a/java/kotlin-extractor/src/main/kotlin/KotlinFileExtractor.kt +++ b/java/kotlin-extractor/src/main/kotlin/KotlinFileExtractor.kt @@ -1645,8 +1645,9 @@ open class KotlinFileExtractor( extractMethodAndParameterTypeAccesses: Boolean, typeSubstitution: TypeSubstitution?, classTypeArgsIncludingOuterClasses: List? - ) : Label = - forceExtractFunction( + ) : Label { + val sourceLoc = tw.getLocation(f.parentClassOrNull ?: f) + return forceExtractFunction( f, parentId, extractBody = false, @@ -1656,6 +1657,7 @@ open class KotlinFileExtractor( classTypeArgsIncludingOuterClasses, overriddenAttributes = OverriddenFunctionAttributes( + sourceLoc = sourceLoc, visibility = DescriptorVisibilities.PUBLIC, modality = Modality.OPEN ) @@ -1666,7 +1668,6 @@ open class KotlinFileExtractor( CompilerGeneratedKinds.INTERFACE_FORWARDER.kind ) if (extractBody) { - val realFunctionLocId = tw.getLocation(f) val inheritedDefaultFunction = f.realOverrideTarget val directlyInheritedSymbol = when (f) { @@ -1686,10 +1687,10 @@ open class KotlinFileExtractor( (directlyInheritedSymbol.owner.parentClassOrNull ?: return functionId) .typeWith() - extractExpressionBody(functionId, realFunctionLocId).also { returnId -> + extractExpressionBody(functionId, sourceLoc).also { returnId -> extractRawMethodAccess( f, - realFunctionLocId, + sourceLoc, f.returnType, functionId, returnId, @@ -1702,7 +1703,7 @@ open class KotlinFileExtractor( extractVariableAccess( syntheticParamId, param.type, - realFunctionLocId, + sourceLoc, argParentId, idxOffset + idx, functionId, @@ -1718,7 +1719,7 @@ open class KotlinFileExtractor( callId, -1, returnId, - realFunctionLocId + sourceLoc ) }, null @@ -1726,6 +1727,7 @@ open class KotlinFileExtractor( } } } + } private fun extractFunction( f: IrFunction, diff --git a/java/kotlin-extractor/src/main/kotlin/MetaAnnotationSupport.kt b/java/kotlin-extractor/src/main/kotlin/MetaAnnotationSupport.kt index e215b5ca31da..d5650389448d 100644 --- a/java/kotlin-extractor/src/main/kotlin/MetaAnnotationSupport.kt +++ b/java/kotlin-extractor/src/main/kotlin/MetaAnnotationSupport.kt @@ -96,8 +96,7 @@ class MetaAnnotationSupport( val metaAnnotations = annotationClass.annotations val jvmRepeatable = metaAnnotations.find { - it.symbol.owner.parentAsClass.fqNameWhenAvailable == - JvmAnnotationNames.REPEATABLE_ANNOTATION + it.annotationClass.fqNameWhenAvailable == JvmAnnotationNames.REPEATABLE_ANNOTATION } return if (jvmRepeatable != null) { ((jvmRepeatable.codeQlGetValueArgument(0) as? IrClassReference)?.symbol as? IrClassSymbol) diff --git a/java/kotlin-extractor/src/main/kotlin/utils/versions/v_2_4_20-RC/Kotlin2ComponentRegistrar.kt b/java/kotlin-extractor/src/main/kotlin/utils/versions/v_2_4_20-RC/Kotlin2ComponentRegistrar.kt new file mode 100644 index 000000000000..f5091752633c --- /dev/null +++ b/java/kotlin-extractor/src/main/kotlin/utils/versions/v_2_4_20-RC/Kotlin2ComponentRegistrar.kt @@ -0,0 +1,32 @@ +package com.github.codeql + +import org.jetbrains.kotlin.backend.common.extensions.IrGenerationExtension +import org.jetbrains.kotlin.compiler.plugin.CompilerPluginRegistrar +import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi +import org.jetbrains.kotlin.config.CompilerConfiguration + +@OptIn(ExperimentalCompilerApi::class) +abstract class Kotlin2ComponentRegistrar : CompilerPluginRegistrar() { + override val supportsK2: Boolean + get() = true + + override val pluginId: String + get() = "kotlin-extractor" + + private var extensionStorage: CompilerPluginRegistrar.ExtensionStorage? = null + + override fun ExtensionStorage.registerExtensions(configuration: CompilerConfiguration) { + this@Kotlin2ComponentRegistrar.extensionStorage = this + doRegisterExtensions(configuration) + } + + abstract fun doRegisterExtensions(configuration: CompilerConfiguration) + + protected fun registerExtractorExtension(extension: IrGenerationExtension) { + val storage = extensionStorage + ?: throw IllegalStateException("registerExtractorExtension called before registerExtensions") + with(storage) { + IrGenerationExtension.registerExtension(extension) + } + } +} diff --git a/java/kotlin-extractor/versions.bzl b/java/kotlin-extractor/versions.bzl index f9642c96b788..f31d69b2a226 100644 --- a/java/kotlin-extractor/versions.bzl +++ b/java/kotlin-extractor/versions.bzl @@ -12,6 +12,7 @@ VERSIONS = [ "2.3.0", "2.3.20", "2.4.0", + "2.4.20-RC", ] def _version_to_tuple(v): diff --git a/java/ql/integration-tests/kotlin/all-platforms/diagnostics/kotlin-version-too-new/diagnostics.expected b/java/ql/integration-tests/kotlin/all-platforms/diagnostics/kotlin-version-too-new/diagnostics.expected index 09429027c5d6..613709bfb152 100644 --- a/java/ql/integration-tests/kotlin/all-platforms/diagnostics/kotlin-version-too-new/diagnostics.expected +++ b/java/ql/integration-tests/kotlin/all-platforms/diagnostics/kotlin-version-too-new/diagnostics.expected @@ -1,5 +1,5 @@ { - "markdownMessage": "The Kotlin version installed (`999.999.999`) is too recent for this version of CodeQL. Install a version lower than 2.4.20.", + "markdownMessage": "The Kotlin version installed (`2.4.20`) is too recent for this version of CodeQL. Install a version lower than 2.4.20.", "severity": "error", "source": { "extractorName": "java", diff --git a/java/ql/integration-tests/kotlin/all-platforms/diagnostics/kotlin-version-too-new/fake-kotlinc-source/kotlin/KotlinVersion.java b/java/ql/integration-tests/kotlin/all-platforms/diagnostics/kotlin-version-too-new/fake-kotlinc-source/kotlin/KotlinVersion.java index e4bd4ecb7e10..523d7e1d0d87 100644 --- a/java/ql/integration-tests/kotlin/all-platforms/diagnostics/kotlin-version-too-new/fake-kotlinc-source/kotlin/KotlinVersion.java +++ b/java/ql/integration-tests/kotlin/all-platforms/diagnostics/kotlin-version-too-new/fake-kotlinc-source/kotlin/KotlinVersion.java @@ -2,6 +2,6 @@ public class KotlinVersion { - public static String CURRENT = "999.999.999"; + public static String CURRENT = "2.4.20"; } diff --git a/java/ql/lib/change-notes/2026-08-21-kotlin-2.4.20.md b/java/ql/lib/change-notes/2026-08-21-kotlin-2.4.20.md new file mode 100644 index 000000000000..90dc6183081b --- /dev/null +++ b/java/ql/lib/change-notes/2026-08-21-kotlin-2.4.20.md @@ -0,0 +1,4 @@ +--- +category: minorAnalysis +--- +* Kotlin versions up to 2.4.20-RC are now supported.