@@ -173,19 +173,7 @@ open class KotlinFileExtractor(
173
173
174
174
fun extractTypeParameter (tp : IrTypeParameter , apparentIndex : Int ): Label <out DbTypevariable >? {
175
175
with (" type parameter" , tp) {
176
- val parentId: Label <out DbClassorinterfaceorcallable >? = when (val parent = tp.parent) {
177
- is IrFunction -> useFunction(parent)
178
- is IrClass -> useClassSource(parent)
179
- else -> {
180
- logger.errorElement(" Unexpected type parameter parent" , tp)
181
- null
182
- }
183
- }
184
-
185
- if (parentId == null ) {
186
- return null
187
- }
188
-
176
+ val parentId = getTypeParameterParentLabel(tp) ? : return null
189
177
val id = tw.getLabelFor<DbTypevariable >(getTypeParameterLabel(tp))
190
178
191
179
// Note apparentIndex does not necessarily equal `tp.index`, because at least constructor type parameters
@@ -334,17 +322,7 @@ open class KotlinFileExtractor(
334
322
val typeParamSubstitution =
335
323
when (argsIncludingOuterClasses) {
336
324
null -> { x: IrType , _: TypeContext , _: IrPluginContext -> x.toRawType() }
337
- else -> {
338
- makeTypeGenericSubstitutionMap(c, argsIncludingOuterClasses).let {
339
- { x: IrType , useContext: TypeContext , pluginContext: IrPluginContext ->
340
- x.substituteTypeAndArguments(
341
- it,
342
- useContext,
343
- pluginContext
344
- )
345
- }
346
- }
347
- }
325
+ else -> makeGenericSubstitutionFunction(c, argsIncludingOuterClasses)
348
326
}
349
327
350
328
c.declarations.map {
@@ -511,12 +489,12 @@ open class KotlinFileExtractor(
511
489
return FieldResult (instanceId, instanceName)
512
490
}
513
491
514
- private fun extractValueParameter (vp : IrValueParameter , parent : Label <out DbCallable >, idx : Int , typeSubstitution : TypeSubstitution ? , parentSourceDeclaration : Label <out DbCallable >, classTypeArgsIncludingOuterClasses : List <IrTypeArgument >? , extractTypeAccess : Boolean ): TypeResults {
492
+ private fun extractValueParameter (vp : IrValueParameter , parent : Label <out DbCallable >, idx : Int , typeSubstitution : TypeSubstitution ? , parentSourceDeclaration : Label <out DbCallable >, classTypeArgsIncludingOuterClasses : List <IrTypeArgument >? , extractTypeAccess : Boolean , locOverride : Label < DbLocation > ? = null ): TypeResults {
515
493
with (" value parameter" , vp) {
516
- val location = getLocation(vp, classTypeArgsIncludingOuterClasses)
494
+ val location = locOverride ? : getLocation(vp, classTypeArgsIncludingOuterClasses)
517
495
val id = useValueParameter(vp, parent)
518
496
if (extractTypeAccess) {
519
- extractTypeAccessRecursive(vp.type, location, id, - 1 )
497
+ extractTypeAccessRecursive(typeSubstitution?. let { it(vp.type, TypeContext . OTHER , pluginContext) } ? : vp.type, location, id, - 1 )
520
498
}
521
499
return extractValueParameter(id, vp.type, vp.name.asString(), location, parent, idx, typeSubstitution, useValueParameter(vp, parentSourceDeclaration), vp.isVararg)
522
500
}
@@ -676,7 +654,7 @@ open class KotlinFileExtractor(
676
654
}
677
655
}
678
656
679
- fun extractFunction (f : IrFunction , parentId : Label <out DbReftype >, extractBody : Boolean , extractMethodAndParameterTypeAccesses : Boolean , typeSubstitution : TypeSubstitution ? , classTypeArgsIncludingOuterClasses : List <IrTypeArgument >? , idOverride : Label <DbMethod >? = null): Label <out DbCallable >? {
657
+ fun extractFunction (f : IrFunction , parentId : Label <out DbReftype >, extractBody : Boolean , extractMethodAndParameterTypeAccesses : Boolean , typeSubstitution : TypeSubstitution ? , classTypeArgsIncludingOuterClasses : List <IrTypeArgument >? , idOverride : Label <DbMethod >? = null, locOverride : Label < DbLocation > ? = null ): Label <out DbCallable >? {
680
658
if (isFake(f)) return null
681
659
682
660
with (" function" , f) {
@@ -694,21 +672,21 @@ open class KotlinFileExtractor(
694
672
useFunction<DbCallable >(f, parentId, classTypeArgsIncludingOuterClasses, noReplace = true )
695
673
696
674
val sourceDeclaration =
697
- if (typeSubstitution != null )
675
+ if (typeSubstitution != null && idOverride == null )
698
676
useFunction(f)
699
677
else
700
678
id
701
679
702
680
val extReceiver = f.extensionReceiverParameter
703
681
val idxOffset = if (extReceiver != null ) 1 else 0
704
682
val paramTypes = f.valueParameters.mapIndexed { i, vp ->
705
- extractValueParameter(vp, id, i + idxOffset, typeSubstitution, sourceDeclaration, classTypeArgsIncludingOuterClasses, extractTypeAccess = extractMethodAndParameterTypeAccesses)
683
+ extractValueParameter(vp, id, i + idxOffset, typeSubstitution, sourceDeclaration, classTypeArgsIncludingOuterClasses, extractTypeAccess = extractMethodAndParameterTypeAccesses, locOverride )
706
684
}
707
685
val allParamTypes = if (extReceiver != null ) {
708
686
val extendedType = useType(extReceiver.type)
709
687
tw.writeKtExtensionFunctions(id.cast<DbMethod >(), extendedType.javaResult.id, extendedType.kotlinResult.id)
710
688
711
- val t = extractValueParameter(extReceiver, id, 0 , null , sourceDeclaration, classTypeArgsIncludingOuterClasses, extractTypeAccess = extractMethodAndParameterTypeAccesses)
689
+ val t = extractValueParameter(extReceiver, id, 0 , null , sourceDeclaration, classTypeArgsIncludingOuterClasses, extractTypeAccess = extractMethodAndParameterTypeAccesses, locOverride )
712
690
listOf (t) + paramTypes
713
691
} else {
714
692
paramTypes
@@ -718,7 +696,7 @@ open class KotlinFileExtractor(
718
696
719
697
val substReturnType = typeSubstitution?.let { it(f.returnType, TypeContext .RETURN , pluginContext) } ? : f.returnType
720
698
721
- val locId = getLocation(f, classTypeArgsIncludingOuterClasses)
699
+ val locId = locOverride ? : getLocation(f, classTypeArgsIncludingOuterClasses)
722
700
723
701
if (f.symbol is IrConstructorSymbol ) {
724
702
val unitType = useType(pluginContext.irBuiltIns.unitType, TypeContext .RETURN )
@@ -738,7 +716,7 @@ open class KotlinFileExtractor(
738
716
tw.writeMethodsKotlinType(methodId, returnType.kotlinResult.id)
739
717
740
718
if (extractMethodAndParameterTypeAccesses) {
741
- extractTypeAccessRecursive(f.returnType , locId, id, - 1 )
719
+ extractTypeAccessRecursive(substReturnType , locId, id, - 1 )
742
720
}
743
721
744
722
if (shortName.nameInDB != shortName.kotlinName) {
@@ -4014,7 +3992,12 @@ open class KotlinFileExtractor(
4014
3992
helper.extractParameterToFieldAssignmentInConstructor(" <fn>" , functionType, fieldId, 0 , 1 )
4015
3993
4016
3994
// add implementation function
4017
- extractFunction(samMember, classId, extractBody = false , extractMethodAndParameterTypeAccesses = true , null , null , ids.function)
3995
+ val classTypeArgs = (e.type as ? IrSimpleType )?.arguments
3996
+ val typeSub = classTypeArgs?.let { makeGenericSubstitutionFunction(typeOwner, it) }
3997
+
3998
+ fun trySub (t : IrType , context : TypeContext ) = if (typeSub == null ) t else typeSub(t, context, pluginContext)
3999
+
4000
+ extractFunction(samMember, classId, extractBody = false , extractMethodAndParameterTypeAccesses = true , typeSub, classTypeArgs, idOverride = ids.function, locOverride = tw.getLocation(e))
4018
4001
4019
4002
// body
4020
4003
val blockId = tw.getFreshIdLabel<DbBlock >()
@@ -4037,7 +4020,7 @@ open class KotlinFileExtractor(
4037
4020
4038
4021
// Call to original `invoke`:
4039
4022
val callId = tw.getFreshIdLabel<DbMethodaccess >()
4040
- val callType = useType(samMember.returnType)
4023
+ val callType = useType(trySub( samMember.returnType, TypeContext . RETURN ) )
4041
4024
tw.writeExprs_methodaccess(callId, callType.javaResult.id, returnId, 0 )
4042
4025
tw.writeExprsKotlinType(callId, callType.kotlinResult.id)
4043
4026
extractCommonExpr(callId)
@@ -4061,7 +4044,7 @@ open class KotlinFileExtractor(
4061
4044
4062
4045
fun extractArgument (p : IrValueParameter , idx : Int , parent : Label <out DbExprparent >) {
4063
4046
val argsAccessId = tw.getFreshIdLabel<DbVaraccess >()
4064
- val paramType = useType(p.type)
4047
+ val paramType = useType(trySub( p.type, TypeContext . OTHER ) )
4065
4048
tw.writeExprs_varaccess(argsAccessId, paramType.javaResult.id, parent, idx)
4066
4049
tw.writeExprsKotlinType(argsAccessId, paramType.kotlinResult.id)
4067
4050
extractCommonExpr(argsAccessId)
0 commit comments