@@ -96,7 +96,7 @@ open class KotlinFileExtractor(
9696 }
9797 }
9898
99- fun extractTypeParameter (tp : IrTypeParameter ): Label <out DbTypevariable > {
99+ fun extractTypeParameter (tp : IrTypeParameter , apparentIndex : Int ): Label <out DbTypevariable > {
100100 val id = tw.getLabelFor<DbTypevariable >(getTypeParameterLabel(tp))
101101
102102 val parentId: Label <out DbClassorinterfaceorcallable > = when (val parent = tp.parent) {
@@ -108,7 +108,10 @@ open class KotlinFileExtractor(
108108 }
109109 }
110110
111- tw.writeTypeVars(id, tp.name.asString(), tp.index, 0 , parentId)
111+ // Note apparentIndex does not necessarily equal `tp.index`, because at least constructor type parameters
112+ // have indices offset from the type parameters of the constructed class (i.e. the parameter S of
113+ // `class Generic<T> { public <S> Generic(T t, S s) { ... } }` will have `tp.index` 1, not 0).
114+ tw.writeTypeVars(id, tp.name.asString(), apparentIndex, 0 , parentId)
112115 val locId = tw.getLocation(tp)
113116 tw.writeHasLocation(id, locId)
114117
@@ -266,7 +269,7 @@ open class KotlinFileExtractor(
266269
267270 extractEnclosingClass(c, id, locId, listOf ())
268271
269- c.typeParameters.map { extractTypeParameter(it) }
272+ c.typeParameters.mapIndexed { idx, it -> extractTypeParameter(it, idx ) }
270273 c.declarations.map { extractDeclaration(it) }
271274 extractObjectInitializerFunction(c, id)
272275 if (c.isNonCompanionObject) {
@@ -451,7 +454,7 @@ open class KotlinFileExtractor(
451454 fun extractFunction (f : IrFunction , parentId : Label <out DbReftype >, extractBody : Boolean , typeSubstitution : TypeSubstitution ? , classTypeArgs : List <IrTypeArgument >? ): Label <out DbCallable > {
452455 declarationStack.push(f)
453456
454- f.typeParameters.map { extractTypeParameter(it) }
457+ getFunctionTypeParameters(f).mapIndexed { idx, it -> extractTypeParameter(it, idx ) }
455458
456459 val locId = tw.getLocation(f)
457460
0 commit comments