Skip to content

Commit 0f83586

Browse files
committed
Kotlin 2.4.0: Address peer review
* Update documentation to only claim support for 2.4.0x * Python test code; remove newlines between imports. * Sync comments between kotlin 1.8 and 1.9 * Update code comments to attach where actually relevant, and improve comments on IrMemberAccessExpression<*>.extensionReceiverParameterIndex()
1 parent 1b785a8 commit 0f83586

8 files changed

Lines changed: 10 additions & 11 deletions

File tree

docs/codeql/reusables/supported-versions-compilers.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
Java,"Java 7 to 26 [6]_","javac (OpenJDK and Oracle JDK),
2222

2323
Eclipse compiler for Java (ECJ) [7]_",``.java``
24-
Kotlin,"Kotlin 1.8.0 to 2.4.\ *x*","kotlinc",``.kt``
24+
Kotlin,"Kotlin 1.8.0 to 2.4.0\ *x*","kotlinc",``.kt``
2525
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`` [8]_"
2626
Python [9]_,"2.7, 3.5, 3.6, 3.7, 3.8, 3.9, 3.10, 3.11, 3.12, 3.13",Not applicable,``.py``
2727
Ruby [10]_,"up to 3.3",Not applicable,"``.rb``, ``.erb``, ``.gemspec``, ``Gemfile``"

java/kotlin-extractor/src/main/kotlin/utils/versions/v_1_8_0/Kotlin2ComponentRegistrar.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ abstract class Kotlin2ComponentRegistrar : ComponentRegistrar {
2828

2929
fun registerExtractorExtension(extension: IrGenerationExtension) {
3030
val p = project ?: throw IllegalStateException("registerExtractorExtension called before registerProjectComponents")
31+
// Register with LoadingOrder.LAST to ensure the extractor runs after other
32+
// IR generation plugins (like kotlinx.serialization) have generated their code.
3133
val extensionPoint = p.extensionArea.getExtensionPoint(IrGenerationExtension.extensionPointName)
3234
extensionPoint.registerExtension(extension, LoadingOrder.LAST, p)
3335
}

java/kotlin-extractor/src/main/kotlin/utils/versions/v_2_4_0/IrCompat.kt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,33 +30,36 @@ val IrFunction.codeQlExtensionReceiverParameter: IrValueParameter?
3030
get() = parameters.firstOrNull { it.kind == org.jetbrains.kotlin.ir.declarations.IrParameterKind.ExtensionReceiver }
3131

3232
// Helper: get the offset of value arguments in the arguments list
33-
// In 2.4.0, arguments[] includes dispatch/extension receivers before regular params
3433
private fun IrMemberAccessExpression<*>.valueArgumentOffset(): Int {
3534
val owner = symbol.owner as? IrFunction ?: return 0
3635
return owner.parameters.count { it.kind != org.jetbrains.kotlin.ir.declarations.IrParameterKind.Regular }
3736
}
3837

3938
// IrMemberAccessExpression: valueArgumentsCount
39+
// In 2.4.0, arguments[] includes dispatch/extension receivers before regular params
4040
val IrMemberAccessExpression<*>.codeQlValueArgumentsCount: Int
4141
get() = arguments.size - valueArgumentOffset()
4242

4343
// IrMemberAccessExpression: getValueArgument
44+
// In 2.4.0, arguments[] includes dispatch/extension receivers before regular params
4445
fun IrMemberAccessExpression<*>.codeQlGetValueArgument(index: Int): IrExpression? = arguments[index + valueArgumentOffset()]
4546

4647
// IrMemberAccessExpression: putValueArgument
48+
// In 2.4.0, arguments[] includes dispatch/extension receivers before regular params
4749
fun IrMemberAccessExpression<*>.codeQlPutValueArgument(index: Int, value: IrExpression?) {
4850
arguments[index + valueArgumentOffset()] = value
4951
}
5052

51-
// IrMemberAccessExpression: extensionReceiver
52-
// For IrCall/IrFunctionReference, look at symbol.owner (IrFunction) directly.
53-
// For IrPropertyReference, symbol.owner is IrProperty; use the getter's parameters instead.
53+
// Re-add accessor for the extensionReceiver property removed in Kotlin 2.4.0.
5454
val IrMemberAccessExpression<*>.codeQlExtensionReceiver: IrExpression?
5555
get() {
5656
val erp = extensionReceiverParameterIndex() ?: return null
5757
return arguments[erp]
5858
}
5959

60+
// Find the argument index corresponding to the extension receiver parameter.
61+
// Calls and function references expose an IrFunction owner directly; property
62+
// references need to look through their getter or setter.
6063
private fun IrMemberAccessExpression<*>.extensionReceiverParameterIndex(): Int? {
6164
// Direct function owner (IrCall, IrFunctionReference, etc.)
6265
(symbol.owner as? IrFunction)?.codeQlExtensionReceiverParameter?.let {
@@ -118,4 +121,3 @@ fun codeQlAnnotationFromSymbolOwner(
118121

119122
fun codeQlAnnotationFromSymbolOwner(type: IrType, symbol: IrConstructorSymbol): IrConstructorCall =
120123
IrAnnotationImpl.fromSymbolOwner(type, symbol)
121-

java/ql/integration-tests/kotlin/all-platforms/enhanced-nullability/test.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import pathlib
2-
32
import pytest
43

54

java/ql/integration-tests/kotlin/all-platforms/external-property-overloads/test.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import commands
2-
32
import pytest
43

54

java/ql/integration-tests/kotlin/all-platforms/file_classes/test.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import commands
2-
32
import pytest
43

54

java/ql/integration-tests/kotlin/all-platforms/java-interface-redeclares-tostring/test.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import commands
2-
32
import pytest
43

54

java/ql/integration-tests/kotlin/all-platforms/kotlin_java_lowering_wildcards/test.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import commands
2-
32
import pytest
43

54

0 commit comments

Comments
 (0)