Skip to content

Commit

Permalink
Kotlin: Add support for 2.0.20
Browse files Browse the repository at this point in the history
  • Loading branch information
igfoo committed Jan 10, 2025
1 parent f0a904e commit ae7124a
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 51 deletions.
2 changes: 1 addition & 1 deletion docs/codeql/reusables/supported-versions-compilers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
Java,"Java 7 to 22 [5]_","javac (OpenJDK and Oracle JDK),

Eclipse compiler for Java (ECJ) [6]_",``.java``
Kotlin,"Kotlin 1.5.0 to 2.1.0\ *x*","kotlinc",``.kt``
Kotlin,"Kotlin 1.5.0 to 2.1.20\ *x*","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",Not applicable,``.py``
Ruby [9]_,"up to 3.3",Not applicable,"``.rb``, ``.erb``, ``.gemspec``, ``Gemfile``"
Expand Down
8 changes: 4 additions & 4 deletions java/kotlin-extractor/src/main/kotlin/KotlinFileExtractor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2305,7 +2305,7 @@ open class KotlinFileExtractor(
// synthesised and inherit the annotation from the delegate (which given it has
// @NotNull, is likely written in Java)
JvmAnnotationNames.JETBRAINS_NOT_NULL_ANNOTATION.takeUnless {
t.isNullable() ||
t.isNullableCodeQL() ||
primitiveTypeMapping.getPrimitiveInfo(t) != null ||
hasExistingAnnotation(it)
}
Expand Down Expand Up @@ -3987,7 +3987,7 @@ open class KotlinFileExtractor(
target.parent
} else {
val st = extensionReceiverParameter.type as? IrSimpleType
if (isNullable != null && st?.isNullable() != isNullable) {
if (isNullable != null && st?.isNullableCodeQL() != isNullable) {
verboseln("Nullablility of type didn't match")
return false
}
Expand Down Expand Up @@ -4633,9 +4633,9 @@ open class KotlinFileExtractor(
val isPrimitiveArrayCreation = !isBuiltinCallKotlin(c, "arrayOf")
val elementType =
if (isPrimitiveArrayCreation) {
c.type.getArrayElementType(pluginContext.irBuiltIns)
c.type.getArrayElementTypeCodeQL(pluginContext.irBuiltIns)
} else {
// TODO: is there any reason not to always use getArrayElementType?
// TODO: is there any reason not to always use getArrayElementTypeCodeQL?
if (c.typeArgumentsCount == 1) {
c.getTypeArgument(0).also {
if (it == null) {
Expand Down
32 changes: 16 additions & 16 deletions java/kotlin-extractor/src/main/kotlin/KotlinUsesExtractor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ open class KotlinUsesExtractor(
private fun getInvariantNullableArrayType(arrayType: IrSimpleType): IrSimpleType =
if (arrayType.isPrimitiveArray()) arrayType
else {
val componentType = arrayType.getArrayElementType(pluginContext.irBuiltIns)
val componentType = arrayType.getArrayElementTypeCodeQL(pluginContext.irBuiltIns)
val componentTypeBroadened =
when (componentType) {
is IrSimpleType ->
Expand All @@ -707,7 +707,7 @@ open class KotlinUsesExtractor(
val unchanged =
componentType == componentTypeBroadened &&
(arrayType.arguments[0] as? IrTypeProjection)?.variance == Variance.INVARIANT &&
componentType.isNullable()
componentType.isNullableCodeQL()
if (unchanged) arrayType
else
IrSimpleTypeImpl(
Expand All @@ -722,7 +722,7 @@ open class KotlinUsesExtractor(
Kotlin arrays can be broken down as:
isArray(t)
|- t.isBoxedArray
|- t.isBoxedArrayCodeQL
| |- t.isArray() e.g. Array<Boolean>, Array<Boolean?>
| |- t.isNullableArray() e.g. Array<Boolean>?, Array<Boolean?>?
|- t.isPrimitiveArray() e.g. BooleanArray
Expand All @@ -732,7 +732,7 @@ open class KotlinUsesExtractor(
Primitive arrays are represented as e.g. boolean[].
*/

private fun isArray(t: IrType) = t.isBoxedArray || t.isPrimitiveArray()
private fun isArray(t: IrType) = t.isBoxedArrayCodeQL || t.isPrimitiveArray()

data class ArrayInfo(
val elementTypeResults: TypeResults,
Expand Down Expand Up @@ -773,7 +773,7 @@ open class KotlinUsesExtractor(
) {
pluginContext.irBuiltIns.anyType
} else {
t.getArrayElementType(pluginContext.irBuiltIns)
t.getArrayElementTypeCodeQL(pluginContext.irBuiltIns)
}

val recInfo = useArrayType(elementType, t.isPrimitiveArray())
Expand Down Expand Up @@ -861,7 +861,7 @@ open class KotlinUsesExtractor(
if (
(context == TypeContext.RETURN ||
(context == TypeContext.OTHER && otherIsPrimitive)) &&
!s.isNullable() &&
!s.isNullableCodeQL() &&
getKotlinType(s)?.hasEnhancedNullability() != true &&
primitiveName != null
) {
Expand All @@ -877,7 +877,7 @@ open class KotlinUsesExtractor(
val kotlinClassId = useClassInstance(kotlinClass, listOf()).typeResult.id
val kotlinResult =
if (true) TypeResult(fakeKotlinType(), "TODO", "TODO")
else if (s.isNullable()) {
else if (s.isNullableCodeQL()) {
val kotlinSignature =
"$kotlinPackageName.$kotlinClassName?" // TODO: Is this right?
val kotlinLabel = "@\"kt_type;nullable;$kotlinPackageName.$kotlinClassName\""
Expand Down Expand Up @@ -919,21 +919,21 @@ open class KotlinUsesExtractor(
return extractErrorType()
}
}
(s.isBoxedArray && s.arguments.isNotEmpty()) || s.isPrimitiveArray() -> {
(s.isBoxedArrayCodeQL && s.arguments.isNotEmpty()) || s.isPrimitiveArray() -> {
val arrayInfo = useArrayType(s, false)
return arrayInfo.componentTypeResults
}
owner is IrClass -> {
val args = if (s.codeQlIsRawType()) null else s.arguments

return useSimpleTypeClass(owner, args, s.isNullable())
return useSimpleTypeClass(owner, args, s.isNullableCodeQL())
}
owner is IrTypeParameter -> {
val javaResult = useTypeParameter(owner)
val aClassId = makeClass("kotlin", "TypeParam") // TODO: Wrong
val kotlinResult =
if (true) TypeResult(fakeKotlinType(), "TODO", "TODO")
else if (s.isNullable()) {
else if (s.isNullableCodeQL()) {
val kotlinSignature = "${javaResult.signature}?" // TODO: Wrong
val kotlinLabel = "@\"kt_type;nullable;type_param\"" // TODO: Wrong
val kotlinId: Label<DbKt_nullable_type> =
Expand Down Expand Up @@ -1217,7 +1217,7 @@ open class KotlinUsesExtractor(
}

private fun extendsAdditionAllowed(t: IrType) =
if (t.isBoxedArray) {
if (t.isBoxedArrayCodeQL) {
if (t is IrSimpleType) {
arrayExtendsAdditionAllowed(t)
} else {
Expand Down Expand Up @@ -1510,7 +1510,7 @@ open class KotlinUsesExtractor(
}
} else {
t.classOrNull?.let { tCls ->
if (t.isBoxedArray) {
if (t.isBoxedArrayCodeQL) {
(t.arguments.singleOrNull() as? IrTypeProjection)?.let { elementTypeArg
->
val elementType = elementTypeArg.type
Expand All @@ -1523,7 +1523,7 @@ open class KotlinUsesExtractor(
)
return tCls
.typeWithArguments(listOf(newArg))
.codeQlWithHasQuestionMark(t.isNullable())
.codeQlWithHasQuestionMark(t.isNullableCodeQL())
}
}
}
Expand Down Expand Up @@ -2103,12 +2103,12 @@ open class KotlinUsesExtractor(
}

if (owner is IrClass) {
if (t.isBoxedArray) {
val elementType = t.getArrayElementType(pluginContext.irBuiltIns)
if (t.isBoxedArrayCodeQL) {
val elementType = t.getArrayElementTypeCodeQL(pluginContext.irBuiltIns)
val erasedElementType = erase(elementType)
return owner
.typeWith(erasedElementType)
.codeQlWithHasQuestionMark(t.isNullable())
.codeQlWithHasQuestionMark(t.isNullableCodeQL())
}

return if (t.arguments.isNotEmpty())
Expand Down
10 changes: 5 additions & 5 deletions java/kotlin-extractor/src/main/kotlin/utils/TypeSubstitution.kt
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private fun IrSimpleType.substituteTypeArguments(
}
}

return IrSimpleTypeImpl(classifier, isNullable(), newArguments, annotations)
return IrSimpleTypeImpl(classifier, isNullableCodeQL(), newArguments, annotations)
}

/**
Expand Down Expand Up @@ -100,7 +100,7 @@ private fun subProjectedType(
else {
val newProjectedType =
substitutedTypeArg.type.let {
if (t.isNullable()) it.codeQlWithHasQuestionMark(true) else it
if (t.isNullableCodeQL()) it.codeQlWithHasQuestionMark(true) else it
}
val newVariance = combineVariance(outerVariance, substitutedTypeArg.variance)
makeTypeProjection(newProjectedType, newVariance)
Expand All @@ -117,7 +117,7 @@ private fun IrTypeArgument.upperBound(context: IrPluginContext) =
when (this.variance) {
Variance.INVARIANT -> this.type
Variance.IN_VARIANCE ->
if (this.type.isNullable()) context.irBuiltIns.anyNType
if (this.type.isNullableCodeQL()) context.irBuiltIns.anyNType
else context.irBuiltIns.anyType
Variance.OUT_VARIANCE -> this.type
}
Expand All @@ -132,7 +132,7 @@ private fun IrTypeArgument.lowerBound(context: IrPluginContext) =
Variance.INVARIANT -> this.type
Variance.IN_VARIANCE -> this.type
Variance.OUT_VARIANCE ->
if (this.type.isNullable()) context.irBuiltIns.nothingNType
if (this.type.isNullableCodeQL()) context.irBuiltIns.nothingNType
else context.irBuiltIns.nothingType
}
else -> context.irBuiltIns.nothingType
Expand Down Expand Up @@ -215,7 +215,7 @@ fun IrTypeArgument.withQuestionMark(b: Boolean): IrTypeArgument =
this.type.let {
when (it) {
is IrSimpleType ->
if (it.isNullable() == b) this
if (it.isNullableCodeQL() == b) this
else makeTypeProjection(it.codeQlWithHasQuestionMark(b), this.variance)
else -> this
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.github.codeql.utils.versions

import org.jetbrains.kotlin.ir.types.*

fun IrType.isNullableCodeQL(): Boolean =
this.isNullable()

val IrType.isBoxedArrayCodeQL: Boolean by IrType::isBoxedArray

fun IrType.getArrayElementTypeCodeQL(irBuiltIns: IrBuiltIns): IrType =
this.getArrayElementType(irBuiltIns)
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ package com.github.codeql.utils.versions

import org.jetbrains.kotlin.ir.IrBuiltIns

typealias IrBuiltIns = IrBuiltIns
typealias IrBuiltIns = org.jetbrains.kotlin.ir.IrBuiltIns

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.github.codeql.utils.versions

import org.jetbrains.kotlin.ir.types.IrType
import org.jetbrains.kotlin.ir.util.*

fun IrType.isNullableCodeQL(): Boolean =
this.isNullable()

val IrType.isBoxedArrayCodeQL: Boolean by IrType::isBoxedArray

fun IrType.getArrayElementTypeCodeQL(irBuiltIns: IrBuiltIns): IrType =
this.getArrayElementType(irBuiltIns)
Original file line number Diff line number Diff line change
@@ -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.1.10.",
"markdownMessage": "The Kotlin version installed (`999.999.999`) is too recent for this version of CodeQL. Install a version lower than 2.1.30.",
"severity": "error",
"source": {
"extractorName": "java",
Expand Down

0 comments on commit ae7124a

Please sign in to comment.