mirror of
https://github.com/github/codeql.git
synced 2025-12-24 04:36:35 +01:00
Kotlin: Fix handling Unit in various places
This commit is contained in:
@@ -354,12 +354,12 @@ open class KotlinFileExtractor(
|
||||
val paramsSignature = paramTypes.joinToString(separator = ",", prefix = "(", postfix = ")") { it.javaResult.signature!! }
|
||||
|
||||
if (f.symbol is IrConstructorSymbol) {
|
||||
val returnType = useType(erase(f.returnType))
|
||||
val returnType = useType(erase(f.returnType), TypeContext.RETURN)
|
||||
val shortName = if (f.returnType.isAnonymous) "" else f.returnType.classFqName?.shortName()?.asString() ?: f.name.asString()
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
tw.writeConstrs(id as Label<DbConstructor>, shortName, "$shortName$paramsSignature", returnType.javaResult.id, returnType.kotlinResult.id, parentId, id)
|
||||
} else {
|
||||
val returnType = useType(f.returnType)
|
||||
val returnType = useType(f.returnType, TypeContext.RETURN)
|
||||
val shortName = f.name.asString()
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
tw.writeMethods(id as Label<DbMethod>, shortName, "$shortName$paramsSignature", returnType.javaResult.id, returnType.kotlinResult.id, parentId, id)
|
||||
|
||||
@@ -101,11 +101,13 @@ open class KotlinUsesExtractor(
|
||||
this.withSourceFileOfClass(extractClass).extractClassInstance(extractClass, typeArgs)
|
||||
}
|
||||
|
||||
// Extract both the Kotlin and equivalent Java classes, so that we have database entries
|
||||
// for both even if all internal references to the Kotlin type are substituted.
|
||||
extractClassLaterIfExternal(c)
|
||||
substituteClass?.let { extractClassLaterIfExternal(it) }
|
||||
})
|
||||
// Extract both the Kotlin and equivalent Java classes, so that we have database entries
|
||||
// for both even if all internal references to the Kotlin type are substituted.
|
||||
// TODO: Should we do this inside the label initialisation? That would require all
|
||||
// initialisers of the label to do it.
|
||||
extractClassLaterIfExternal(c)
|
||||
|
||||
return UseClassInstanceResult(TypeResult(classLabel, extractClass.fqNameWhenAvailable?.asString(), classId.shortName), extractClass)
|
||||
}
|
||||
@@ -280,9 +282,10 @@ open class KotlinUsesExtractor(
|
||||
return classId
|
||||
}
|
||||
fun primitiveType(kotlinClass: IrClass, primitiveName: String?,
|
||||
otherIsPrimitive: Boolean,
|
||||
javaPackageName: String, javaClassName: String,
|
||||
kotlinPackageName: String, kotlinClassName: String): TypeResults {
|
||||
val javaResult = if (context != TypeContext.GENERIC_ARGUMENT && !s.hasQuestionMark && primitiveName != null) {
|
||||
val javaResult = if ((context == TypeContext.RETURN || (context == TypeContext.OTHER && otherIsPrimitive)) && !s.hasQuestionMark && primitiveName != null) {
|
||||
val label: Label<DbPrimitive> = tw.getLabelFor("@\"type;$primitiveName\"", {
|
||||
tw.writePrimitives(it, primitiveName)
|
||||
})
|
||||
@@ -327,8 +330,9 @@ XXX delete?
|
||||
*/
|
||||
primitiveInfo != null -> return primitiveType(
|
||||
s.classifier.owner as IrClass,
|
||||
primitiveInfo.primitiveName, primitiveInfo.javaPackageName,
|
||||
primitiveInfo.javaClassName, primitiveInfo.kotlinPackageName, primitiveInfo.kotlinClassName
|
||||
primitiveInfo.primitiveName, primitiveInfo.otherIsPrimitive,
|
||||
primitiveInfo.javaPackageName, primitiveInfo.javaClassName,
|
||||
primitiveInfo.kotlinPackageName, primitiveInfo.kotlinClassName
|
||||
)
|
||||
/*
|
||||
TODO: Test case: nullable and has-question-mark type variables:
|
||||
@@ -644,13 +648,13 @@ class X {
|
||||
fun useValueParameter(vp: IrValueParameter): Label<out DbParam> =
|
||||
tw.getLabelFor(getValueParameterLabel(vp))
|
||||
|
||||
fun getFieldLabel(p: IrField): String {
|
||||
val parentId = useDeclarationParent(p.parent)
|
||||
return "@\"field;{$parentId};${p.name.asString()}\""
|
||||
fun getFieldLabel(f: IrField): String {
|
||||
val parentId = useDeclarationParent(f.parent)
|
||||
return "@\"field;{$parentId};${f.name.asString()}\""
|
||||
}
|
||||
|
||||
fun useField(p: IrField): Label<out DbField> =
|
||||
tw.getLabelFor(getFieldLabel(p))
|
||||
fun useField(f: IrField): Label<out DbField> =
|
||||
tw.getLabelFor(getFieldLabel(f))
|
||||
|
||||
fun getPropertyLabel(p: IrProperty): String {
|
||||
val parentId = useDeclarationParent(p.parent)
|
||||
|
||||
@@ -4,28 +4,29 @@ import org.jetbrains.kotlin.ir.types.IdSignatureValues
|
||||
|
||||
data class PrimitiveTypeInfo(
|
||||
val primitiveName: String?,
|
||||
val otherIsPrimitive: Boolean,
|
||||
val javaPackageName: String, val javaClassName: String,
|
||||
val kotlinPackageName: String, val kotlinClassName: String
|
||||
)
|
||||
|
||||
val primitiveTypeMapping = mapOf(
|
||||
IdSignatureValues._byte to PrimitiveTypeInfo("byte", "java.lang", "Byte", "kotlin", "Byte"),
|
||||
IdSignatureValues._short to PrimitiveTypeInfo("short", "java.lang", "Short", "kotlin", "Short"),
|
||||
IdSignatureValues._int to PrimitiveTypeInfo("int", "java.lang", "Integer", "kotlin", "Int"),
|
||||
IdSignatureValues._long to PrimitiveTypeInfo("long", "java.lang", "Long", "kotlin", "Long"),
|
||||
IdSignatureValues._byte to PrimitiveTypeInfo("byte", true, "java.lang", "Byte", "kotlin", "Byte"),
|
||||
IdSignatureValues._short to PrimitiveTypeInfo("short", true, "java.lang", "Short", "kotlin", "Short"),
|
||||
IdSignatureValues._int to PrimitiveTypeInfo("int", true, "java.lang", "Integer", "kotlin", "Int"),
|
||||
IdSignatureValues._long to PrimitiveTypeInfo("long", true, "java.lang", "Long", "kotlin", "Long"),
|
||||
|
||||
IdSignatureValues.uByte to PrimitiveTypeInfo("byte", "kotlin", "UByte", "kotlin", "UByte"),
|
||||
IdSignatureValues.uShort to PrimitiveTypeInfo("short", "kotlin", "UShort", "kotlin", "UShort"),
|
||||
IdSignatureValues.uInt to PrimitiveTypeInfo("int", "kotlin", "UInt", "kotlin", "UInt"),
|
||||
IdSignatureValues.uLong to PrimitiveTypeInfo("long", "kotlin", "ULong", "kotlin", "ULong"),
|
||||
IdSignatureValues.uByte to PrimitiveTypeInfo("byte", true, "kotlin", "UByte", "kotlin", "UByte"),
|
||||
IdSignatureValues.uShort to PrimitiveTypeInfo("short", true, "kotlin", "UShort", "kotlin", "UShort"),
|
||||
IdSignatureValues.uInt to PrimitiveTypeInfo("int", true, "kotlin", "UInt", "kotlin", "UInt"),
|
||||
IdSignatureValues.uLong to PrimitiveTypeInfo("long", true, "kotlin", "ULong", "kotlin", "ULong"),
|
||||
|
||||
IdSignatureValues._double to PrimitiveTypeInfo("double", "java.lang", "Double", "kotlin", "Double"),
|
||||
IdSignatureValues._float to PrimitiveTypeInfo("float", "java.lang", "Float", "kotlin", "Float"),
|
||||
IdSignatureValues._double to PrimitiveTypeInfo("double", true, "java.lang", "Double", "kotlin", "Double"),
|
||||
IdSignatureValues._float to PrimitiveTypeInfo("float", true, "java.lang", "Float", "kotlin", "Float"),
|
||||
|
||||
IdSignatureValues._boolean to PrimitiveTypeInfo("boolean", "java.lang", "Boolean", "kotlin", "Boolean"),
|
||||
IdSignatureValues._boolean to PrimitiveTypeInfo("boolean", true, "java.lang", "Boolean", "kotlin", "Boolean"),
|
||||
|
||||
IdSignatureValues._char to PrimitiveTypeInfo("char", "java.lang", "Character", "kotlin", "Char"),
|
||||
IdSignatureValues._char to PrimitiveTypeInfo("char", true, "java.lang", "Character", "kotlin", "Char"),
|
||||
|
||||
IdSignatureValues.unit to PrimitiveTypeInfo("void", "java.lang", "Void", "kotlin", "Nothing"), // TODO: Is this right?
|
||||
IdSignatureValues.nothing to PrimitiveTypeInfo(null, "java.lang", "Void", "kotlin", "Nothing"), // TODO: Is this right?
|
||||
IdSignatureValues.unit to PrimitiveTypeInfo("void", false, "kotlin", "Unit", "kotlin", "Unit"),
|
||||
IdSignatureValues.nothing to PrimitiveTypeInfo(null, true, "java.lang", "Void", "kotlin", "Nothing"),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user