@@ -20,6 +20,7 @@ import org.jetbrains.kotlin.ir.symbols.*
20
20
import org.jetbrains.kotlin.ir.types.*
21
21
import org.jetbrains.kotlin.ir.util.*
22
22
import org.jetbrains.kotlin.name.FqName
23
+ import org.jetbrains.kotlin.types.Variance
23
24
import org.jetbrains.kotlin.util.OperatorNameConventions
24
25
import java.io.Closeable
25
26
import java.util.*
@@ -3748,6 +3749,17 @@ open class KotlinFileExtractor(
3748
3749
}
3749
3750
}
3750
3751
3752
+ /* *
3753
+ * Extracts a single wildcard type access expression with no enclosing callable and statement.
3754
+ */
3755
+ private fun extractWildcardTypeAccess (type : TypeResults , location : Label <DbLocation >, parent : Label <out DbExprparent >, idx : Int ): Label <out DbExpr > {
3756
+ val id = tw.getFreshIdLabel<DbWildcardtypeaccess >()
3757
+ tw.writeExprs_wildcardtypeaccess(id, type.javaResult.id, parent, idx)
3758
+ tw.writeExprsKotlinType(id, type.kotlinResult.id)
3759
+ tw.writeHasLocation(id, location)
3760
+ return id
3761
+ }
3762
+
3751
3763
/* *
3752
3764
* Extracts a single type access expression with no enclosing callable and statement.
3753
3765
*/
@@ -3772,15 +3784,36 @@ open class KotlinFileExtractor(
3772
3784
return id
3773
3785
}
3774
3786
3787
+ /* *
3788
+ * Extracts a type argument type access, introducing a wildcard type access if appropriate, or directly calling
3789
+ * `extractTypeAccessRecursive` if the argument is invariant.
3790
+ * No enclosing callable and statement is extracted, this is useful for type access extraction in field declarations.
3791
+ */
3792
+ private fun extractWildcardTypeAccessRecursive (t : IrTypeArgument , location : Label <DbLocation >, parent : Label <out DbExprparent >, idx : Int ) {
3793
+ val typeLabels by lazy { TypeResults (getTypeArgumentLabel(t), TypeResult (fakeKotlinType(), " TODO" , " TODO" )) }
3794
+ when (t) {
3795
+ is IrStarProjection -> extractWildcardTypeAccess(typeLabels, location, parent, idx)
3796
+ is IrTypeProjection -> when (t.variance) {
3797
+ Variance .INVARIANT -> extractTypeAccessRecursive(t.type, location, parent, idx, TypeContext .GENERIC_ARGUMENT )
3798
+ else -> {
3799
+ val wildcardLabel = extractWildcardTypeAccess(typeLabels, location, parent, idx)
3800
+ // Mimic a Java extractor oddity, that it uses the child index to indicate what kind of wildcard this is
3801
+ val boundChildIdx = if (t.variance == Variance .OUT_VARIANCE ) 0 else 1
3802
+ extractTypeAccessRecursive(t.type, location, wildcardLabel, boundChildIdx, TypeContext .GENERIC_ARGUMENT )
3803
+ }
3804
+ }
3805
+ }
3806
+ }
3807
+
3775
3808
/* *
3776
3809
* Extracts a type access expression and its child type access expressions in case of a generic type. Nested generics are also handled.
3777
3810
* No enclosing callable and statement is extracted, this is useful for type access extraction in field declarations.
3778
3811
*/
3779
3812
private fun extractTypeAccessRecursive (t : IrType , location : Label <DbLocation >, parent : Label <out DbExprparent >, idx : Int , typeContext : TypeContext = TypeContext .OTHER ): Label <out DbExpr > {
3780
3813
val typeAccessId = extractTypeAccess(useType(t, typeContext), location, parent, idx)
3781
3814
if (t is IrSimpleType ) {
3782
- t.arguments.filterIsInstance< IrType >(). forEachIndexed { argIdx, arg ->
3783
- extractTypeAccessRecursive (arg, location, typeAccessId, argIdx, TypeContext . GENERIC_ARGUMENT )
3815
+ t.arguments.forEachIndexed { argIdx, arg ->
3816
+ extractWildcardTypeAccessRecursive (arg, location, typeAccessId, argIdx)
3784
3817
}
3785
3818
}
3786
3819
return typeAccessId
0 commit comments