mirror of
https://github.com/github/codeql.git
synced 2025-12-22 11:46:32 +01:00
Suppress use of function type parameters in the context of building a $defaults method
These methods have erased signatures and no type parameters, so anything that refers to one must itself be erased. For signatures this would be easy, but for potentially deep default expressions these types can occur in various places and need erasing at each occurence.
This commit is contained in:
@@ -878,7 +878,7 @@ open class KotlinFileExtractor(
|
||||
// n + o'th parameter, where `o` is the parameter offset caused by adding any dispatch receiver to the parameter list.
|
||||
// Note we don't need to add the extension receiver here because `useValueParameter` always assumes an extension receiver
|
||||
// will be prepended if one exists.
|
||||
DeclarationStackAdjuster(f, OverriddenFunctionAttributes(id, id, locId, nonSyntheticParams)).use {
|
||||
DeclarationStackAdjuster(f, OverriddenFunctionAttributes(id, id, locId, nonSyntheticParams, typeParameters = listOf())).use {
|
||||
val realParamsVarId = getValueParameterLabel(id, parameterTypes.size - 2)
|
||||
val intType = pluginContext.irBuiltIns.intType
|
||||
val paramIdxOffset = listOf(dispatchReceiver, f.extensionReceiverParameter).count { it != null }
|
||||
@@ -5363,7 +5363,7 @@ open class KotlinFileExtractor(
|
||||
stack.firstOrNull { it.first == f } ?.second
|
||||
}
|
||||
|
||||
data class OverriddenFunctionAttributes(val id: Label<out DbCallable>? = null, val sourceDeclarationId: Label<out DbCallable>? = null, val sourceLoc: Label<DbLocation>? = null, val valueParameters: List<IrValueParameter>? = null)
|
||||
data class OverriddenFunctionAttributes(val id: Label<out DbCallable>? = null, val sourceDeclarationId: Label<out DbCallable>? = null, val sourceLoc: Label<DbLocation>? = null, val valueParameters: List<IrValueParameter>? = null, val typeParameters: List<IrTypeParameter>? = null)
|
||||
|
||||
private fun peekDeclStackAsDeclarationParent(elementToReportOn: IrElement): IrDeclarationParent? {
|
||||
val trapWriter = tw
|
||||
|
||||
@@ -658,6 +658,19 @@ open class KotlinUsesExtractor(
|
||||
RETURN, GENERIC_ARGUMENT, OTHER
|
||||
}
|
||||
|
||||
private fun isOnDeclarationStackWithoutTypeParameters(f: IrFunction) =
|
||||
this is KotlinFileExtractor && this.declarationStack.findOverriddenAttributes(f)?.typeParameters?.isEmpty() == true
|
||||
|
||||
private fun isUnavailableTypeParameter(t: IrType) =
|
||||
t is IrSimpleType && t.classifier.owner.let { owner ->
|
||||
owner is IrTypeParameter && owner.parent.let { parent ->
|
||||
parent is IrFunction && isOnDeclarationStackWithoutTypeParameters(parent)
|
||||
}
|
||||
}
|
||||
|
||||
private fun argIsUnavailableTypeParameter(t: IrTypeArgument) =
|
||||
t is IrTypeProjection && isUnavailableTypeParameter(t.type)
|
||||
|
||||
private fun useSimpleType(s: IrSimpleType, context: TypeContext): TypeResults {
|
||||
if (s.abbreviation != null) {
|
||||
// TODO: Extract this information
|
||||
@@ -729,11 +742,13 @@ open class KotlinUsesExtractor(
|
||||
}
|
||||
|
||||
owner is IrClass -> {
|
||||
val args = if (s.isRawType()) null else s.arguments
|
||||
val args = if (s.isRawType() || s.arguments.any { argIsUnavailableTypeParameter(it) }) null else s.arguments
|
||||
|
||||
return useSimpleTypeClass(owner, args, s.isNullable())
|
||||
}
|
||||
owner is IrTypeParameter -> {
|
||||
if (isUnavailableTypeParameter(s))
|
||||
return useType(erase(s), context)
|
||||
val javaResult = useTypeParameter(owner)
|
||||
val aClassId = makeClass("kotlin", "TypeParam") // TODO: Wrong
|
||||
val kotlinResult = if (true) TypeResult(fakeKotlinType(), "TODO", "TODO") else
|
||||
|
||||
Reference in New Issue
Block a user