@@ -19,6 +19,9 @@ import org.jetbrains.kotlin.ir.expressions.*
19
19
import org.jetbrains.kotlin.ir.symbols.*
20
20
import org.jetbrains.kotlin.ir.types.*
21
21
import org.jetbrains.kotlin.ir.util.*
22
+ import org.jetbrains.kotlin.load.java.sources.JavaSourceElement
23
+ import org.jetbrains.kotlin.load.java.structure.JavaClass
24
+ import org.jetbrains.kotlin.load.java.structure.JavaTypeParameter
22
25
import org.jetbrains.kotlin.name.FqName
23
26
import org.jetbrains.kotlin.types.Variance
24
27
import org.jetbrains.kotlin.util.OperatorNameConventions
@@ -172,7 +175,7 @@ open class KotlinFileExtractor(
172
175
}
173
176
}
174
177
175
- fun extractTypeParameter (tp : IrTypeParameter , apparentIndex : Int ): Label <out DbTypevariable >? {
178
+ fun extractTypeParameter (tp : IrTypeParameter , apparentIndex : Int , javaTypeParameter : JavaTypeParameter ? ): Label <out DbTypevariable >? {
176
179
with (" type parameter" , tp) {
177
180
val parentId = getTypeParameterParentLabel(tp) ? : return null
178
181
val id = tw.getLabelFor<DbTypevariable >(getTypeParameterLabel(tp))
@@ -184,10 +187,21 @@ open class KotlinFileExtractor(
184
187
val locId = tw.getLocation(tp)
185
188
tw.writeHasLocation(id, locId)
186
189
190
+ // Annoyingly, we have no obvious way to pair up the bounds of an IrTypeParameter and a JavaTypeParameter
191
+ // because JavaTypeParameter provides a Collection not an ordered list, so we can only do our best here:
192
+ fun tryGetJavaBound (idx : Int ) =
193
+ when (tp.superTypes.size) {
194
+ 1 -> javaTypeParameter?.upperBounds?.singleOrNull()
195
+ else -> (javaTypeParameter?.upperBounds as ? List )?.getOrNull(idx)
196
+ }
197
+
187
198
tp.superTypes.forEachIndexed { boundIdx, bound ->
188
199
if (! (bound.isAny() || bound.isNullableAny())) {
189
200
tw.getLabelFor<DbTypebound >(" @\" bound;$boundIdx ;{$id }\" " ) {
190
- tw.writeTypeBounds(it, useType(bound).javaResult.id.cast<DbReftype >(), boundIdx, id)
201
+ // Note we don't look for @JvmSuppressWildcards here because it doesn't seem to have any impact
202
+ // on kotlinc adding wildcards to type parameter bounds.
203
+ val boundWithWildcards = addJavaLoweringWildcards(bound, true , tryGetJavaBound(tp.index))
204
+ tw.writeTypeBounds(it, useType(boundWithWildcards).javaResult.id.cast<DbReftype >(), boundIdx, id)
191
205
}
192
206
}
193
207
}
@@ -383,7 +397,9 @@ open class KotlinFileExtractor(
383
397
384
398
extractEnclosingClass(c, id, locId, listOf ())
385
399
386
- c.typeParameters.mapIndexed { idx, param -> extractTypeParameter(param, idx) }
400
+ val javaClass = (c.source as ? JavaSourceElement )?.javaElement as ? JavaClass
401
+
402
+ c.typeParameters.mapIndexed { idx, param -> extractTypeParameter(param, idx, javaClass?.typeParameters?.getOrNull(idx)) }
387
403
if (extractDeclarations) {
388
404
c.declarations.map { extractDeclaration(it, extractPrivateMembers = extractPrivateMembers, extractFunctionBodies = extractFunctionBodies) }
389
405
if (extractStaticInitializer)
@@ -675,7 +691,8 @@ open class KotlinFileExtractor(
675
691
with (" function" , f) {
676
692
DeclarationStackAdjuster (f).use {
677
693
678
- getFunctionTypeParameters(f).mapIndexed { idx, tp -> extractTypeParameter(tp, idx) }
694
+ val javaMethod = getJavaMethod(f)
695
+ getFunctionTypeParameters(f).mapIndexed { idx, tp -> extractTypeParameter(tp, idx, javaMethod?.typeParameters?.getOrNull(idx)) }
679
696
680
697
val id =
681
698
idOverride
@@ -709,7 +726,7 @@ open class KotlinFileExtractor(
709
726
710
727
val paramsSignature = allParamTypes.joinToString(separator = " ," , prefix = " (" , postfix = " )" ) { it.javaResult.signature!! }
711
728
712
- val adjustedReturnType = addJavaLoweringWildcards(getAdjustedReturnType(f), false , getJavaMethod(f) ?.returnType)
729
+ val adjustedReturnType = addJavaLoweringWildcards(getAdjustedReturnType(f), false , javaMethod ?.returnType)
713
730
val substReturnType = typeSubstitution?.let { it(adjustedReturnType, TypeContext .RETURN , pluginContext) } ? : adjustedReturnType
714
731
715
732
val locId = locOverride ? : getLocation(f, classTypeArgsIncludingOuterClasses)
0 commit comments