[FE 1.0] Don't report CAST_NEVER_SUCCEEDS on stub types

^KT-49829 Fixed
This commit is contained in:
Victor Petukhov
2021-12-17 10:29:14 +03:00
committed by teamcity
parent 37d163d417
commit 8e2b90b5db
10 changed files with 71 additions and 11 deletions
@@ -24,10 +24,8 @@ import org.jetbrains.kotlin.resolve.DescriptorUtils
import org.jetbrains.kotlin.resolve.calls.inference.isCaptured
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
import org.jetbrains.kotlin.types.*
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
import org.jetbrains.kotlin.types.checker.NewCapturedType
import org.jetbrains.kotlin.types.checker.NewCapturedTypeConstructor
import org.jetbrains.kotlin.types.checker.intersectTypes
import org.jetbrains.kotlin.types.checker.*
import org.jetbrains.kotlin.types.model.SimpleTypeMarker
import org.jetbrains.kotlin.types.model.TypeArgumentMarker
import org.jetbrains.kotlin.types.model.TypeVariableTypeConstructorMarker
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
@@ -391,3 +389,13 @@ private fun NewCapturedType.unCaptureTopLevelType(): UnwrappedType {
fun KotlinType?.shouldBeUpdated() =
this == null || contains { it is StubTypeForBuilderInference || it.constructor is TypeVariableTypeConstructorMarker || it.isError }
fun KotlinType.isStubType() = this is AbstractStubType || isDefNotNullStubType<AbstractStubType>()
fun KotlinType.isStubTypeForVariableInSubtyping(): Boolean =
this is StubTypeForTypeVariablesInSubtyping || isDefNotNullStubType<StubTypeForTypeVariablesInSubtyping>()
fun KotlinType.isStubTypeForBuilderInference(): Boolean =
this is StubTypeForBuilderInference || isDefNotNullStubType<StubTypeForBuilderInference>()
private inline fun <reified S : AbstractStubType> KotlinType.isDefNotNullStubType() = this is DefinitelyNotNullType && this.original is S
@@ -30,6 +30,9 @@ import org.jetbrains.kotlin.utils.addIfNotNull
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
import org.jetbrains.kotlin.types.typeUtil.isSignedOrUnsignedNumberType as classicIsSignedOrUnsignedNumberType
import org.jetbrains.kotlin.types.typeUtil.isStubTypeForVariableInSubtyping as isSimpleTypeStubTypeForVariableInSubtyping
import org.jetbrains.kotlin.types.typeUtil.isStubTypeForBuilderInference as isSimpleTypeStubTypeForBuilderInference
import org.jetbrains.kotlin.types.typeUtil.isStubType as isSimpleTypeStubType
interface ClassicTypeSystemContext : TypeSystemInferenceExtensionContext, TypeSystemCommonBackendContext {
override fun TypeConstructorMarker.isDenotable(): Boolean {
@@ -86,20 +89,17 @@ interface ClassicTypeSystemContext : TypeSystemInferenceExtensionContext, TypeSy
override fun SimpleTypeMarker.isStubType(): Boolean {
require(this is SimpleType, this::errorMessage)
return this is AbstractStubType || isDefNotNullStubType<AbstractStubType>()
return this.isSimpleTypeStubType()
}
private inline fun <reified S : AbstractStubType> SimpleTypeMarker.isDefNotNullStubType() =
this is DefinitelyNotNullType && this.original is S
override fun SimpleTypeMarker.isStubTypeForVariableInSubtyping(): Boolean {
require(this is SimpleType, this::errorMessage)
return this is StubTypeForTypeVariablesInSubtyping || isDefNotNullStubType<StubTypeForTypeVariablesInSubtyping>()
return this.isSimpleTypeStubTypeForVariableInSubtyping()
}
override fun SimpleTypeMarker.isStubTypeForBuilderInference(): Boolean {
require(this is SimpleType, this::errorMessage)
return this is StubTypeForBuilderInference || isDefNotNullStubType<StubTypeForBuilderInference>()
return this.isSimpleTypeStubTypeForBuilderInference()
}
override fun TypeConstructorMarker.unwrapStubTypeVariableConstructor(): TypeConstructorMarker {