Skip to content

Commit 6119670

Browse files
committed
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.
1 parent 720cf56 commit 6119670

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,7 @@ open class KotlinFileExtractor(
878878
// n + o'th parameter, where `o` is the parameter offset caused by adding any dispatch receiver to the parameter list.
879879
// Note we don't need to add the extension receiver here because `useValueParameter` always assumes an extension receiver
880880
// will be prepended if one exists.
881-
DeclarationStackAdjuster(f, OverriddenFunctionAttributes(id, id, locId, nonSyntheticParams)).use {
881+
DeclarationStackAdjuster(f, OverriddenFunctionAttributes(id, id, locId, nonSyntheticParams, typeParameters = listOf())).use {
882882
val realParamsVarId = getValueParameterLabel(id, parameterTypes.size - 2)
883883
val intType = pluginContext.irBuiltIns.intType
884884
val paramIdxOffset = listOf(dispatchReceiver, f.extensionReceiverParameter).count { it != null }
@@ -5363,7 +5363,7 @@ open class KotlinFileExtractor(
53635363
stack.firstOrNull { it.first == f } ?.second
53645364
}
53655365

5366-
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)
5366+
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)
53675367

53685368
private fun peekDeclStackAsDeclarationParent(elementToReportOn: IrElement): IrDeclarationParent? {
53695369
val trapWriter = tw

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,19 @@ open class KotlinUsesExtractor(
658658
RETURN, GENERIC_ARGUMENT, OTHER
659659
}
660660

661+
private fun isOnDeclarationStackWithoutTypeParameters(f: IrFunction) =
662+
this is KotlinFileExtractor && this.declarationStack.findOverriddenAttributes(f)?.typeParameters?.isEmpty() == true
663+
664+
private fun isUnavailableTypeParameter(t: IrType) =
665+
t is IrSimpleType && t.classifier.owner.let { owner ->
666+
owner is IrTypeParameter && owner.parent.let { parent ->
667+
parent is IrFunction && isOnDeclarationStackWithoutTypeParameters(parent)
668+
}
669+
}
670+
671+
private fun argIsUnavailableTypeParameter(t: IrTypeArgument) =
672+
t is IrTypeProjection && isUnavailableTypeParameter(t.type)
673+
661674
private fun useSimpleType(s: IrSimpleType, context: TypeContext): TypeResults {
662675
if (s.abbreviation != null) {
663676
// TODO: Extract this information
@@ -729,11 +742,13 @@ open class KotlinUsesExtractor(
729742
}
730743

731744
owner is IrClass -> {
732-
val args = if (s.isRawType()) null else s.arguments
745+
val args = if (s.isRawType() || s.arguments.any { argIsUnavailableTypeParameter(it) }) null else s.arguments
733746

734747
return useSimpleTypeClass(owner, args, s.isNullable())
735748
}
736749
owner is IrTypeParameter -> {
750+
if (isUnavailableTypeParameter(s))
751+
return useType(erase(s), context)
737752
val javaResult = useTypeParameter(owner)
738753
val aClassId = makeClass("kotlin", "TypeParam") // TODO: Wrong
739754
val kotlinResult = if (true) TypeResult(fakeKotlinType(), "TODO", "TODO") else

0 commit comments

Comments
 (0)