From da15f0ffe899be791578c4c0237f463220c5ca5f Mon Sep 17 00:00:00 2001 From: Ivan Kochurkin Date: Thu, 3 Jun 2021 15:02:09 +0300 Subject: [PATCH] [FIR] Consider fullyExpandedType instead of original type in isSubtypeForTypeMismatch, consider lookupTag in `isError` method --- .../kotlin/fir/analysis/checkers/FirHelpers.kt | 6 ++++-- .../org/jetbrains/kotlin/fir/types/ConeTypeContext.kt | 3 ++- .../unsafeVarianceInAliasedFunctionalType.fir.kt | 11 ----------- .../unsafeVarianceInAliasedFunctionalType.kt | 1 + .../diagnostics/testsWithStdLib/java/functionN.fir.kt | 2 +- 5 files changed, 8 insertions(+), 15 deletions(-) delete mode 100644 compiler/testData/diagnostics/tests/generics/projectionsScope/unsafeVarianceInAliasedFunctionalType.fir.kt diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/FirHelpers.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/FirHelpers.kt index 26320124afc..5a7dae1fab8 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/FirHelpers.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/FirHelpers.kt @@ -382,8 +382,10 @@ private fun lowerThanBound(context: ConeInferenceContext, argument: ConeKotlinTy fun FirMemberDeclaration.isInlineOnly(): Boolean = isInline && hasAnnotation(INLINE_ONLY_ANNOTATION_CLASS_ID) fun isSubtypeForTypeMismatch(context: ConeInferenceContext, subtype: ConeKotlinType, supertype: ConeKotlinType): Boolean { - return AbstractTypeChecker.isSubtypeOf(context, subtype, supertype) - || isSubtypeOfForFunctionalTypeReturningUnit(context.session.typeContext, subtype, supertype) + val subtypeFullyExpanded = subtype.fullyExpandedType(context.session) + val supertypeFullyExpanded = supertype.fullyExpandedType(context.session) + return AbstractTypeChecker.isSubtypeOf(context, subtypeFullyExpanded, supertypeFullyExpanded) + || isSubtypeOfForFunctionalTypeReturningUnit(context.session.typeContext, subtypeFullyExpanded, supertypeFullyExpanded) } private fun isSubtypeOfForFunctionalTypeReturningUnit( diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/ConeTypeContext.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/ConeTypeContext.kt index dbe8bab5c8a..e7845098e68 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/ConeTypeContext.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/ConeTypeContext.kt @@ -85,7 +85,8 @@ interface ConeTypeContext : TypeSystemContext, TypeSystemOptimizationContext, Ty override fun KotlinTypeMarker.isError(): Boolean { assert(this is ConeKotlinType) - return this is ConeClassErrorType || this is ConeKotlinErrorType || this.typeConstructor().isError() + return this is ConeClassErrorType || this is ConeKotlinErrorType || this.typeConstructor().isError() || + (this is ConeClassLikeType && this.lookupTag is ConeClassLikeErrorLookupTag) } override fun KotlinTypeMarker.isUninferredParameter(): Boolean { diff --git a/compiler/testData/diagnostics/tests/generics/projectionsScope/unsafeVarianceInAliasedFunctionalType.fir.kt b/compiler/testData/diagnostics/tests/generics/projectionsScope/unsafeVarianceInAliasedFunctionalType.fir.kt deleted file mode 100644 index ca0d9acc14c..00000000000 --- a/compiler/testData/diagnostics/tests/generics/projectionsScope/unsafeVarianceInAliasedFunctionalType.fir.kt +++ /dev/null @@ -1,11 +0,0 @@ -class Foo(val baz: Baz) - -class Bar { - val foo: Foo<*> = TODO() - - fun bar(): Baz { - return foo.baz - } -} - -typealias Baz = (@UnsafeVariance T) -> Unit diff --git a/compiler/testData/diagnostics/tests/generics/projectionsScope/unsafeVarianceInAliasedFunctionalType.kt b/compiler/testData/diagnostics/tests/generics/projectionsScope/unsafeVarianceInAliasedFunctionalType.kt index 05ad642e149..708a7a96125 100644 --- a/compiler/testData/diagnostics/tests/generics/projectionsScope/unsafeVarianceInAliasedFunctionalType.kt +++ b/compiler/testData/diagnostics/tests/generics/projectionsScope/unsafeVarianceInAliasedFunctionalType.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL class Foo(val baz: Baz) class Bar { diff --git a/compiler/testData/diagnostics/testsWithStdLib/java/functionN.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/java/functionN.fir.kt index 0d24f1a4e8a..6f3227c76ac 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/java/functionN.fir.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/java/functionN.fir.kt @@ -47,7 +47,7 @@ fun main() { a.baz(listOf()) a.manyParams(null) - a.manyParams(any>()) + a.manyParams(any>()) // Potentially, this would have better to forbid calling manyParams, too. // But it might be complicated because we need to match that it is an override