mirror of
https://github.com/github/codeql.git
synced 2025-12-24 04:36:35 +01:00
Merge pull request #10262 from igfoo/igfoo/useArrayType
Kotlin: Avoid unsafe casts in useArrayType
This commit is contained in:
@@ -541,6 +541,12 @@ open class KotlinUsesExtractor(
|
|||||||
|
|
||||||
private fun useArrayType(arrayType: IrSimpleType, componentType: IrType, elementType: IrType, dimensions: Int, isPrimitiveArray: Boolean): TypeResults {
|
private fun useArrayType(arrayType: IrSimpleType, componentType: IrType, elementType: IrType, dimensions: Int, isPrimitiveArray: Boolean): TypeResults {
|
||||||
|
|
||||||
|
val arrayClass = arrayType.classifier.owner
|
||||||
|
if (arrayClass !is IrClass) {
|
||||||
|
error("Unexpected owner type for array type: ${arrayClass.javaClass}")
|
||||||
|
return extractErrorType()
|
||||||
|
}
|
||||||
|
|
||||||
// Ensure we extract Array<Int> as Integer[], not int[], for example:
|
// Ensure we extract Array<Int> as Integer[], not int[], for example:
|
||||||
fun nullableIfNotPrimitive(type: IrType) = if (type.isPrimitiveType() && !isPrimitiveArray) type.makeNullable() else type
|
fun nullableIfNotPrimitive(type: IrType) = if (type.isPrimitiveType() && !isPrimitiveArray) type.makeNullable() else type
|
||||||
|
|
||||||
@@ -557,7 +563,7 @@ open class KotlinUsesExtractor(
|
|||||||
dimensions,
|
dimensions,
|
||||||
componentTypeResults.javaResult.id)
|
componentTypeResults.javaResult.id)
|
||||||
|
|
||||||
extractClassSupertypes(arrayType.classifier.owner as IrClass, it, ExtractSupertypesMode.Specialised(arrayType.arguments))
|
extractClassSupertypes(arrayClass, it, ExtractSupertypesMode.Specialised(arrayType.arguments))
|
||||||
|
|
||||||
// array.length
|
// array.length
|
||||||
val length = tw.getLabelFor<DbField>("@\"field;{$it};length\"")
|
val length = tw.getLabelFor<DbField>("@\"field;{$it};length\"")
|
||||||
@@ -582,7 +588,7 @@ open class KotlinUsesExtractor(
|
|||||||
componentTypeResults.javaResult.signature + "[]",
|
componentTypeResults.javaResult.signature + "[]",
|
||||||
javaShortName)
|
javaShortName)
|
||||||
|
|
||||||
val arrayClassResult = useSimpleTypeClass(arrayType.classifier.owner as IrClass, arrayType.arguments, arrayType.hasQuestionMark)
|
val arrayClassResult = useSimpleTypeClass(arrayClass, arrayType.arguments, arrayType.hasQuestionMark)
|
||||||
return TypeResults(javaResult, arrayClassResult.kotlinResult)
|
return TypeResults(javaResult, arrayClassResult.kotlinResult)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user