K2: generate bounds for inner-class based raw types properly
#KT-58579 Fixed
This commit is contained in:
committed by
Space Team
parent
4e2067a163
commit
27afee8683
@@ -22,6 +22,7 @@ import org.jetbrains.kotlin.name.ClassId
|
|||||||
import org.jetbrains.kotlin.name.FqName
|
import org.jetbrains.kotlin.name.FqName
|
||||||
import org.jetbrains.kotlin.name.StandardClassIds
|
import org.jetbrains.kotlin.name.StandardClassIds
|
||||||
import org.jetbrains.kotlin.types.Variance
|
import org.jetbrains.kotlin.types.Variance
|
||||||
|
import org.jetbrains.kotlin.utils.addToStdlib.runUnless
|
||||||
import org.jetbrains.kotlin.utils.exceptions.errorWithAttachment
|
import org.jetbrains.kotlin.utils.exceptions.errorWithAttachment
|
||||||
|
|
||||||
private fun ClassId.toConeFlexibleType(
|
private fun ClassId.toConeFlexibleType(
|
||||||
@@ -195,9 +196,9 @@ private fun JavaClassifierType.toConeKotlinTypeForFlexibleBound(
|
|||||||
?.toFirRegularClassSymbol(session)?.typeParameterSymbols
|
?.toFirRegularClassSymbol(session)?.typeParameterSymbols
|
||||||
// Given `C<T : X>`, `C` -> `C<X>..C<*>?`.
|
// Given `C<T : X>`, `C` -> `C<X>..C<*>?`.
|
||||||
when (mode) {
|
when (mode) {
|
||||||
FirJavaTypeConversionMode.ANNOTATION_MEMBER -> Array(classifier.typeParameters.size) { ConeStarProjection }
|
FirJavaTypeConversionMode.ANNOTATION_MEMBER -> Array(classifier.allTypeParametersNumber()) { ConeStarProjection }
|
||||||
else -> typeParameterSymbols?.getProjectionsForRawType(session)
|
else -> typeParameterSymbols?.getProjectionsForRawType(session)
|
||||||
?: Array(classifier.typeParameters.size) { ConeStarProjection }
|
?: Array(classifier.allTypeParametersNumber()) { ConeStarProjection }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -234,6 +235,16 @@ private fun JavaClassifierType.toConeKotlinTypeForFlexibleBound(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun JavaClass.allTypeParametersNumber(): Int {
|
||||||
|
var current: JavaClass? = this
|
||||||
|
var result = 0
|
||||||
|
while (current != null) {
|
||||||
|
result += current.typeParameters.size
|
||||||
|
current = if (current.isStatic) null else current.outerClass
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
// Returns true for covariant read-only container that has mutable pair with invariant parameter
|
// Returns true for covariant read-only container that has mutable pair with invariant parameter
|
||||||
// List<in A> does not make sense, but MutableList<in A> does
|
// List<in A> does not make sense, but MutableList<in A> does
|
||||||
// Same for Map<K, in V>
|
// Same for Map<K, in V>
|
||||||
|
|||||||
-19
@@ -1,19 +0,0 @@
|
|||||||
// ISSUE: KT-58579
|
|
||||||
// FILE: Invariant.java
|
|
||||||
public class Invariant<T> {}
|
|
||||||
|
|
||||||
// FILE: Generic.java
|
|
||||||
public class Generic<T> {
|
|
||||||
public class Inner {}
|
|
||||||
public static Invariant<? extends Generic.Inner> foo() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// FILE: Main.kt
|
|
||||||
fun main() {
|
|
||||||
val value = Generic.foo()
|
|
||||||
<!NEW_INFERENCE_ERROR!>value.bar()<!>
|
|
||||||
}
|
|
||||||
|
|
||||||
fun <T> T.bar() {}
|
|
||||||
+1
@@ -1,3 +1,4 @@
|
|||||||
|
// FIR_IDENTICAL
|
||||||
// ISSUE: KT-58579
|
// ISSUE: KT-58579
|
||||||
// FILE: Invariant.java
|
// FILE: Invariant.java
|
||||||
public class Invariant<T> {}
|
public class Invariant<T> {}
|
||||||
|
|||||||
Reference in New Issue
Block a user