@@ -322,17 +322,7 @@ open class KotlinFileExtractor(
322
322
val typeParamSubstitution =
323
323
when (argsIncludingOuterClasses) {
324
324
null -> { x: IrType , _: TypeContext , _: IrPluginContext -> x.toRawType() }
325
- else -> {
326
- makeTypeGenericSubstitutionMap(c, argsIncludingOuterClasses).let {
327
- { x: IrType , useContext: TypeContext , pluginContext: IrPluginContext ->
328
- x.substituteTypeAndArguments(
329
- it,
330
- useContext,
331
- pluginContext
332
- )
333
- }
334
- }
335
- }
325
+ else -> makeGenericSubstitutionFunction(c, argsIncludingOuterClasses)
336
326
}
337
327
338
328
c.declarations.map {
@@ -499,12 +489,12 @@ open class KotlinFileExtractor(
499
489
return FieldResult (instanceId, instanceName)
500
490
}
501
491
502
- 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 {
503
493
with (" value parameter" , vp) {
504
- val location = getLocation(vp, classTypeArgsIncludingOuterClasses)
494
+ val location = locOverride ? : getLocation(vp, classTypeArgsIncludingOuterClasses)
505
495
val id = useValueParameter(vp, parent)
506
496
if (extractTypeAccess) {
507
- extractTypeAccessRecursive(vp.type, location, id, - 1 )
497
+ extractTypeAccessRecursive(typeSubstitution?. let { it(vp.type, TypeContext . OTHER , pluginContext) } ? : vp.type, location, id, - 1 )
508
498
}
509
499
return extractValueParameter(id, vp.type, vp.name.asString(), location, parent, idx, typeSubstitution, useValueParameter(vp, parentSourceDeclaration), vp.isVararg)
510
500
}
@@ -664,7 +654,7 @@ open class KotlinFileExtractor(
664
654
}
665
655
}
666
656
667
- 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 >? {
668
658
if (isFake(f)) return null
669
659
670
660
with (" function" , f) {
@@ -682,21 +672,21 @@ open class KotlinFileExtractor(
682
672
useFunction<DbCallable >(f, parentId, classTypeArgsIncludingOuterClasses, noReplace = true )
683
673
684
674
val sourceDeclaration =
685
- if (typeSubstitution != null )
675
+ if (typeSubstitution != null && idOverride == null )
686
676
useFunction(f)
687
677
else
688
678
id
689
679
690
680
val extReceiver = f.extensionReceiverParameter
691
681
val idxOffset = if (extReceiver != null ) 1 else 0
692
682
val paramTypes = f.valueParameters.mapIndexed { i, vp ->
693
- extractValueParameter(vp, id, i + idxOffset, typeSubstitution, sourceDeclaration, classTypeArgsIncludingOuterClasses, extractTypeAccess = extractMethodAndParameterTypeAccesses)
683
+ extractValueParameter(vp, id, i + idxOffset, typeSubstitution, sourceDeclaration, classTypeArgsIncludingOuterClasses, extractTypeAccess = extractMethodAndParameterTypeAccesses, locOverride )
694
684
}
695
685
val allParamTypes = if (extReceiver != null ) {
696
686
val extendedType = useType(extReceiver.type)
697
687
tw.writeKtExtensionFunctions(id.cast<DbMethod >(), extendedType.javaResult.id, extendedType.kotlinResult.id)
698
688
699
- val t = extractValueParameter(extReceiver, id, 0 , null , sourceDeclaration, classTypeArgsIncludingOuterClasses, extractTypeAccess = extractMethodAndParameterTypeAccesses)
689
+ val t = extractValueParameter(extReceiver, id, 0 , null , sourceDeclaration, classTypeArgsIncludingOuterClasses, extractTypeAccess = extractMethodAndParameterTypeAccesses, locOverride )
700
690
listOf (t) + paramTypes
701
691
} else {
702
692
paramTypes
@@ -706,7 +696,7 @@ open class KotlinFileExtractor(
706
696
707
697
val substReturnType = typeSubstitution?.let { it(f.returnType, TypeContext .RETURN , pluginContext) } ? : f.returnType
708
698
709
- val locId = getLocation(f, classTypeArgsIncludingOuterClasses)
699
+ val locId = locOverride ? : getLocation(f, classTypeArgsIncludingOuterClasses)
710
700
711
701
if (f.symbol is IrConstructorSymbol ) {
712
702
val unitType = useType(pluginContext.irBuiltIns.unitType, TypeContext .RETURN )
@@ -726,7 +716,7 @@ open class KotlinFileExtractor(
726
716
tw.writeMethodsKotlinType(methodId, returnType.kotlinResult.id)
727
717
728
718
if (extractMethodAndParameterTypeAccesses) {
729
- extractTypeAccessRecursive(f.returnType , locId, id, - 1 )
719
+ extractTypeAccessRecursive(substReturnType , locId, id, - 1 )
730
720
}
731
721
732
722
if (shortName.nameInDB != shortName.kotlinName) {
@@ -4002,7 +3992,12 @@ open class KotlinFileExtractor(
4002
3992
helper.extractParameterToFieldAssignmentInConstructor(" <fn>" , functionType, fieldId, 0 , 1 )
4003
3993
4004
3994
// add implementation function
4005
- 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))
4006
4001
4007
4002
// body
4008
4003
val blockId = tw.getFreshIdLabel<DbBlock >()
@@ -4025,7 +4020,7 @@ open class KotlinFileExtractor(
4025
4020
4026
4021
// Call to original `invoke`:
4027
4022
val callId = tw.getFreshIdLabel<DbMethodaccess >()
4028
- val callType = useType(samMember.returnType)
4023
+ val callType = useType(trySub( samMember.returnType, TypeContext . RETURN ) )
4029
4024
tw.writeExprs_methodaccess(callId, callType.javaResult.id, returnId, 0 )
4030
4025
tw.writeExprsKotlinType(callId, callType.kotlinResult.id)
4031
4026
extractCommonExpr(callId)
@@ -4049,7 +4044,7 @@ open class KotlinFileExtractor(
4049
4044
4050
4045
fun extractArgument (p : IrValueParameter , idx : Int , parent : Label <out DbExprparent >) {
4051
4046
val argsAccessId = tw.getFreshIdLabel<DbVaraccess >()
4052
- val paramType = useType(p.type)
4047
+ val paramType = useType(trySub( p.type, TypeContext . OTHER ) )
4053
4048
tw.writeExprs_varaccess(argsAccessId, paramType.javaResult.id, parent, idx)
4054
4049
tw.writeExprsKotlinType(argsAccessId, paramType.kotlinResult.id)
4055
4050
extractCommonExpr(argsAccessId)
0 commit comments