Skip to content

Commit ae7124a

Browse files
committed
Kotlin: Add support for 2.0.20
1 parent f0a904e commit ae7124a

File tree

11 files changed

+51
-51
lines changed

11 files changed

+51
-51
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
Java,"Java 7 to 22 [5]_","javac (OpenJDK and Oracle JDK),
2121

2222
Eclipse compiler for Java (ECJ) [6]_",``.java``
23-
Kotlin,"Kotlin 1.5.0 to 2.1.0\ *x*","kotlinc",``.kt``
23+
Kotlin,"Kotlin 1.5.0 to 2.1.20\ *x*","kotlinc",``.kt``
2424
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]_"
2525
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``
2626
Ruby [9]_,"up to 3.3",Not applicable,"``.rb``, ``.erb``, ``.gemspec``, ``Gemfile``"

java/kotlin-extractor/src/main/kotlin/KotlinFileExtractor.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2305,7 +2305,7 @@ open class KotlinFileExtractor(
23052305
// synthesised and inherit the annotation from the delegate (which given it has
23062306
// @NotNull, is likely written in Java)
23072307
JvmAnnotationNames.JETBRAINS_NOT_NULL_ANNOTATION.takeUnless {
2308-
t.isNullable() ||
2308+
t.isNullableCodeQL() ||
23092309
primitiveTypeMapping.getPrimitiveInfo(t) != null ||
23102310
hasExistingAnnotation(it)
23112311
}
@@ -3987,7 +3987,7 @@ open class KotlinFileExtractor(
39873987
target.parent
39883988
} else {
39893989
val st = extensionReceiverParameter.type as? IrSimpleType
3990-
if (isNullable != null && st?.isNullable() != isNullable) {
3990+
if (isNullable != null && st?.isNullableCodeQL() != isNullable) {
39913991
verboseln("Nullablility of type didn't match")
39923992
return false
39933993
}
@@ -4633,9 +4633,9 @@ open class KotlinFileExtractor(
46334633
val isPrimitiveArrayCreation = !isBuiltinCallKotlin(c, "arrayOf")
46344634
val elementType =
46354635
if (isPrimitiveArrayCreation) {
4636-
c.type.getArrayElementType(pluginContext.irBuiltIns)
4636+
c.type.getArrayElementTypeCodeQL(pluginContext.irBuiltIns)
46374637
} else {
4638-
// TODO: is there any reason not to always use getArrayElementType?
4638+
// TODO: is there any reason not to always use getArrayElementTypeCodeQL?
46394639
if (c.typeArgumentsCount == 1) {
46404640
c.getTypeArgument(0).also {
46414641
if (it == null) {

java/kotlin-extractor/src/main/kotlin/KotlinUsesExtractor.kt

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,7 @@ open class KotlinUsesExtractor(
696696
private fun getInvariantNullableArrayType(arrayType: IrSimpleType): IrSimpleType =
697697
if (arrayType.isPrimitiveArray()) arrayType
698698
else {
699-
val componentType = arrayType.getArrayElementType(pluginContext.irBuiltIns)
699+
val componentType = arrayType.getArrayElementTypeCodeQL(pluginContext.irBuiltIns)
700700
val componentTypeBroadened =
701701
when (componentType) {
702702
is IrSimpleType ->
@@ -707,7 +707,7 @@ open class KotlinUsesExtractor(
707707
val unchanged =
708708
componentType == componentTypeBroadened &&
709709
(arrayType.arguments[0] as? IrTypeProjection)?.variance == Variance.INVARIANT &&
710-
componentType.isNullable()
710+
componentType.isNullableCodeQL()
711711
if (unchanged) arrayType
712712
else
713713
IrSimpleTypeImpl(
@@ -722,7 +722,7 @@ open class KotlinUsesExtractor(
722722
Kotlin arrays can be broken down as:
723723
724724
isArray(t)
725-
|- t.isBoxedArray
725+
|- t.isBoxedArrayCodeQL
726726
| |- t.isArray() e.g. Array<Boolean>, Array<Boolean?>
727727
| |- t.isNullableArray() e.g. Array<Boolean>?, Array<Boolean?>?
728728
|- t.isPrimitiveArray() e.g. BooleanArray
@@ -732,7 +732,7 @@ open class KotlinUsesExtractor(
732732
Primitive arrays are represented as e.g. boolean[].
733733
*/
734734

735-
private fun isArray(t: IrType) = t.isBoxedArray || t.isPrimitiveArray()
735+
private fun isArray(t: IrType) = t.isBoxedArrayCodeQL || t.isPrimitiveArray()
736736

737737
data class ArrayInfo(
738738
val elementTypeResults: TypeResults,
@@ -773,7 +773,7 @@ open class KotlinUsesExtractor(
773773
) {
774774
pluginContext.irBuiltIns.anyType
775775
} else {
776-
t.getArrayElementType(pluginContext.irBuiltIns)
776+
t.getArrayElementTypeCodeQL(pluginContext.irBuiltIns)
777777
}
778778

779779
val recInfo = useArrayType(elementType, t.isPrimitiveArray())
@@ -861,7 +861,7 @@ open class KotlinUsesExtractor(
861861
if (
862862
(context == TypeContext.RETURN ||
863863
(context == TypeContext.OTHER && otherIsPrimitive)) &&
864-
!s.isNullable() &&
864+
!s.isNullableCodeQL() &&
865865
getKotlinType(s)?.hasEnhancedNullability() != true &&
866866
primitiveName != null
867867
) {
@@ -877,7 +877,7 @@ open class KotlinUsesExtractor(
877877
val kotlinClassId = useClassInstance(kotlinClass, listOf()).typeResult.id
878878
val kotlinResult =
879879
if (true) TypeResult(fakeKotlinType(), "TODO", "TODO")
880-
else if (s.isNullable()) {
880+
else if (s.isNullableCodeQL()) {
881881
val kotlinSignature =
882882
"$kotlinPackageName.$kotlinClassName?" // TODO: Is this right?
883883
val kotlinLabel = "@\"kt_type;nullable;$kotlinPackageName.$kotlinClassName\""
@@ -919,21 +919,21 @@ open class KotlinUsesExtractor(
919919
return extractErrorType()
920920
}
921921
}
922-
(s.isBoxedArray && s.arguments.isNotEmpty()) || s.isPrimitiveArray() -> {
922+
(s.isBoxedArrayCodeQL && s.arguments.isNotEmpty()) || s.isPrimitiveArray() -> {
923923
val arrayInfo = useArrayType(s, false)
924924
return arrayInfo.componentTypeResults
925925
}
926926
owner is IrClass -> {
927927
val args = if (s.codeQlIsRawType()) null else s.arguments
928928

929-
return useSimpleTypeClass(owner, args, s.isNullable())
929+
return useSimpleTypeClass(owner, args, s.isNullableCodeQL())
930930
}
931931
owner is IrTypeParameter -> {
932932
val javaResult = useTypeParameter(owner)
933933
val aClassId = makeClass("kotlin", "TypeParam") // TODO: Wrong
934934
val kotlinResult =
935935
if (true) TypeResult(fakeKotlinType(), "TODO", "TODO")
936-
else if (s.isNullable()) {
936+
else if (s.isNullableCodeQL()) {
937937
val kotlinSignature = "${javaResult.signature}?" // TODO: Wrong
938938
val kotlinLabel = "@\"kt_type;nullable;type_param\"" // TODO: Wrong
939939
val kotlinId: Label<DbKt_nullable_type> =
@@ -1217,7 +1217,7 @@ open class KotlinUsesExtractor(
12171217
}
12181218

12191219
private fun extendsAdditionAllowed(t: IrType) =
1220-
if (t.isBoxedArray) {
1220+
if (t.isBoxedArrayCodeQL) {
12211221
if (t is IrSimpleType) {
12221222
arrayExtendsAdditionAllowed(t)
12231223
} else {
@@ -1510,7 +1510,7 @@ open class KotlinUsesExtractor(
15101510
}
15111511
} else {
15121512
t.classOrNull?.let { tCls ->
1513-
if (t.isBoxedArray) {
1513+
if (t.isBoxedArrayCodeQL) {
15141514
(t.arguments.singleOrNull() as? IrTypeProjection)?.let { elementTypeArg
15151515
->
15161516
val elementType = elementTypeArg.type
@@ -1523,7 +1523,7 @@ open class KotlinUsesExtractor(
15231523
)
15241524
return tCls
15251525
.typeWithArguments(listOf(newArg))
1526-
.codeQlWithHasQuestionMark(t.isNullable())
1526+
.codeQlWithHasQuestionMark(t.isNullableCodeQL())
15271527
}
15281528
}
15291529
}
@@ -2103,12 +2103,12 @@ open class KotlinUsesExtractor(
21032103
}
21042104

21052105
if (owner is IrClass) {
2106-
if (t.isBoxedArray) {
2107-
val elementType = t.getArrayElementType(pluginContext.irBuiltIns)
2106+
if (t.isBoxedArrayCodeQL) {
2107+
val elementType = t.getArrayElementTypeCodeQL(pluginContext.irBuiltIns)
21082108
val erasedElementType = erase(elementType)
21092109
return owner
21102110
.typeWith(erasedElementType)
2111-
.codeQlWithHasQuestionMark(t.isNullable())
2111+
.codeQlWithHasQuestionMark(t.isNullableCodeQL())
21122112
}
21132113

21142114
return if (t.arguments.isNotEmpty())

java/kotlin-extractor/src/main/kotlin/utils/TypeSubstitution.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ private fun IrSimpleType.substituteTypeArguments(
6161
}
6262
}
6363

64-
return IrSimpleTypeImpl(classifier, isNullable(), newArguments, annotations)
64+
return IrSimpleTypeImpl(classifier, isNullableCodeQL(), newArguments, annotations)
6565
}
6666

6767
/**
@@ -100,7 +100,7 @@ private fun subProjectedType(
100100
else {
101101
val newProjectedType =
102102
substitutedTypeArg.type.let {
103-
if (t.isNullable()) it.codeQlWithHasQuestionMark(true) else it
103+
if (t.isNullableCodeQL()) it.codeQlWithHasQuestionMark(true) else it
104104
}
105105
val newVariance = combineVariance(outerVariance, substitutedTypeArg.variance)
106106
makeTypeProjection(newProjectedType, newVariance)
@@ -117,7 +117,7 @@ private fun IrTypeArgument.upperBound(context: IrPluginContext) =
117117
when (this.variance) {
118118
Variance.INVARIANT -> this.type
119119
Variance.IN_VARIANCE ->
120-
if (this.type.isNullable()) context.irBuiltIns.anyNType
120+
if (this.type.isNullableCodeQL()) context.irBuiltIns.anyNType
121121
else context.irBuiltIns.anyType
122122
Variance.OUT_VARIANCE -> this.type
123123
}
@@ -132,7 +132,7 @@ private fun IrTypeArgument.lowerBound(context: IrPluginContext) =
132132
Variance.INVARIANT -> this.type
133133
Variance.IN_VARIANCE -> this.type
134134
Variance.OUT_VARIANCE ->
135-
if (this.type.isNullable()) context.irBuiltIns.nothingNType
135+
if (this.type.isNullableCodeQL()) context.irBuiltIns.nothingNType
136136
else context.irBuiltIns.nothingType
137137
}
138138
else -> context.irBuiltIns.nothingType
@@ -215,7 +215,7 @@ fun IrTypeArgument.withQuestionMark(b: Boolean): IrTypeArgument =
215215
this.type.let {
216216
when (it) {
217217
is IrSimpleType ->
218-
if (it.isNullable() == b) this
218+
if (it.isNullableCodeQL() == b) this
219219
else makeTypeProjection(it.codeQlWithHasQuestionMark(b), this.variance)
220220
else -> this
221221
}

java/kotlin-extractor/src/main/kotlin/utils/versions/v_1_5_0/isNullable.kt

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.github.codeql.utils.versions
2+
3+
import org.jetbrains.kotlin.ir.types.*
4+
5+
fun IrType.isNullableCodeQL(): Boolean =
6+
this.isNullable()
7+
8+
val IrType.isBoxedArrayCodeQL: Boolean by IrType::isBoxedArray
9+
10+
fun IrType.getArrayElementTypeCodeQL(irBuiltIns: IrBuiltIns): IrType =
11+
this.getArrayElementType(irBuiltIns)

java/kotlin-extractor/src/main/kotlin/utils/versions/v_1_6_0/IrBuiltIns.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ package com.github.codeql.utils.versions
22

33
import org.jetbrains.kotlin.ir.IrBuiltIns
44

5-
typealias IrBuiltIns = IrBuiltIns
5+
typealias IrBuiltIns = org.jetbrains.kotlin.ir.IrBuiltIns

java/kotlin-extractor/src/main/kotlin/utils/versions/v_2_1_0-Beta1/isNullable.kt

Lines changed: 0 additions & 11 deletions
This file was deleted.

java/kotlin-extractor/src/main/kotlin/utils/versions/v_2_1_20-Beta1/isNullable.kt

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.github.codeql.utils.versions
2+
3+
import org.jetbrains.kotlin.ir.types.IrType
4+
import org.jetbrains.kotlin.ir.util.*
5+
6+
fun IrType.isNullableCodeQL(): Boolean =
7+
this.isNullable()
8+
9+
val IrType.isBoxedArrayCodeQL: Boolean by IrType::isBoxedArray
10+
11+
fun IrType.getArrayElementTypeCodeQL(irBuiltIns: IrBuiltIns): IrType =
12+
this.getArrayElementType(irBuiltIns)

0 commit comments

Comments
 (0)