Implement makeNullableAsSpecified for TypeTemplate properly
This change fixes an SOE in isCastErased:
@JvmStatic
fun isCastErased(supertype: KotlinType, subtype: KotlinType, typeChecker: KotlinTypeChecker): Boolean {
if (supertype.isMarkedNullable || subtype.isMarkedNullable) {
return isCastErased(TypeUtils.makeNotNullable(supertype), TypeUtils.makeNotNullable(subtype), typeChecker)
}
TypeUtils.makeNotNullable(TypeTemplate) should not return the same object
if isMarkedNullable returned true on the instance
#KT-15516 Fixed
This commit is contained in:
+7
-3
@@ -56,11 +56,15 @@ import javax.inject.Inject
|
||||
|
||||
class TypeTemplate(
|
||||
val typeVariable: TypeVariable,
|
||||
val coroutineInferenceData: CoroutineInferenceData
|
||||
) : FlexibleType(typeVariable.originalTypeParameter.builtIns.nothingType, typeVariable.originalTypeParameter.builtIns.nullableAnyType) {
|
||||
val coroutineInferenceData: CoroutineInferenceData,
|
||||
nullable: Boolean = true
|
||||
) : FlexibleType(
|
||||
typeVariable.originalTypeParameter.builtIns.nothingType,
|
||||
typeVariable.originalTypeParameter.builtIns.anyType.makeNullableAsSpecified(nullable)
|
||||
) {
|
||||
override fun replaceAnnotations(newAnnotations: Annotations) = this
|
||||
|
||||
override fun makeNullableAsSpecified(newNullability: Boolean) = this
|
||||
override fun makeNullableAsSpecified(newNullability: Boolean) = TypeTemplate(typeVariable, coroutineInferenceData, newNullability)
|
||||
|
||||
override val delegate: SimpleType
|
||||
get() = upperBound
|
||||
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
// SKIP_TXT
|
||||
class StateMachine<Q> internal constructor() {
|
||||
fun getInputStub(): Q = null as Q
|
||||
}
|
||||
|
||||
fun <T> stateMachine(<!UNUSED_PARAMETER!>block<!>: suspend StateMachine<T>.() -> Unit): StateMachine<T> {
|
||||
return StateMachine<T>()
|
||||
}
|
||||
|
||||
class Problem<F>(){
|
||||
fun getInputStub(): F = null as F
|
||||
|
||||
fun createStateMachine(): StateMachine<F> = stateMachine {
|
||||
val letter = getInputStub()
|
||||
if (letter is Any)
|
||||
println("yes")
|
||||
}
|
||||
}
|
||||
@@ -853,6 +853,12 @@ public class DiagnosticsTestWithStdLibGenerated extends AbstractDiagnosticsTestW
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("kt15516.kt")
|
||||
public void testKt15516() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/kt15516.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("recursiveGenerators.kt")
|
||||
public void testRecursiveGenerators() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/recursiveGenerators.kt");
|
||||
|
||||
Reference in New Issue
Block a user