From 3ea1f7851b2b24b7b2c09702a006807d17371471 Mon Sep 17 00:00:00 2001 From: Dmitrii Gridin Date: Wed, 29 Mar 2023 13:07:01 +0200 Subject: [PATCH] [FIR] add missing resolve to isFinalClassConstructor fix checking for intersection types in CheckIncompatibleTypeVariableUpperBounds we need this resolve, because getEmptyIntersectionTypeKind under the hood uses org.jetbrains.kotlin.resolve.checkers.EmptyIntersectionTypeChecker.computeEmptyIntersectionEmptiness which uses computeByHavingCommonSubtype where we have isFinalClassConstructor() call, so we need to resolve to STATUS phase to get the correct modality ^KT-56543 --- .../org/jetbrains/kotlin/fir/types/ConeInferenceContext.kt | 2 +- .../tests/inference/emptyIntersectionTypes/kt48935.diag.txt | 4 ++-- .../tests/inference/emptyIntersectionTypes/kt48935.kt | 1 - .../tests/inference/emptyIntersectionTypes/kt48935_5.kt | 1 - .../tests/typeParameters/kt46186withEmptyIntersections.kt | 1 - 5 files changed, 3 insertions(+), 6 deletions(-) diff --git a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/ConeInferenceContext.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/ConeInferenceContext.kt index 3d6234f5c24..2dd73eb6d48 100644 --- a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/ConeInferenceContext.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/ConeInferenceContext.kt @@ -303,7 +303,7 @@ interface ConeInferenceContext : TypeSystemInferenceExtensionContext, ConeTypeCo val symbol = toClassLikeSymbol() ?: return false if (symbol is FirAnonymousObjectSymbol) return true val classSymbol = symbol as? FirRegularClassSymbol ?: return false - return classSymbol.fir.modality == Modality.FINAL + return classSymbol.modality == Modality.FINAL } override fun TypeVariableMarker.freshTypeConstructor(): TypeConstructorMarker { diff --git a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt48935.diag.txt b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt48935.diag.txt index 3aeb28cc279..cd9d8450834 100644 --- a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt48935.diag.txt +++ b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt48935.diag.txt @@ -1,7 +1,7 @@ -/kt48935.kt:8:35: warning: parameter 'func' is never used +/kt48935.kt:7:35: warning: parameter 'func' is never used fun exampleGenericFunction(func: V) where T: Base, V: (T) -> Unit { ^ -/kt48935.kt:14:5: warning: type argument for a type parameter T has possible incompatible upper bounds: Base, DoesNotImplementBase (final class and interface) +/kt48935.kt:13:5: warning: type argument for a type parameter T has possible incompatible upper bounds: Base, DoesNotImplementBase (final class and interface) exampleGenericFunction(func) // expected this to be a compilation error as the T: Base constraint should not be satisfied ^ diff --git a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt48935.kt b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt48935.kt index 2f8cae74175..0ffc1386ffa 100644 --- a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt48935.kt +++ b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt48935.kt @@ -1,4 +1,3 @@ -// IGNORE_REVERSED_RESOLVE // FIR_IDENTICAL // RENDER_DIAGNOSTICS_FULL_TEXT interface Base diff --git a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt48935_5.kt b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt48935_5.kt index 355c4312f19..f8e93eac92f 100644 --- a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt48935_5.kt +++ b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt48935_5.kt @@ -1,4 +1,3 @@ -// IGNORE_REVERSED_RESOLVE // FIR_IDENTICAL interface Base diff --git a/compiler/testData/diagnostics/tests/typeParameters/kt46186withEmptyIntersections.kt b/compiler/testData/diagnostics/tests/typeParameters/kt46186withEmptyIntersections.kt index b0664951d46..9e18f1fd557 100644 --- a/compiler/testData/diagnostics/tests/typeParameters/kt46186withEmptyIntersections.kt +++ b/compiler/testData/diagnostics/tests/typeParameters/kt46186withEmptyIntersections.kt @@ -1,4 +1,3 @@ -// IGNORE_REVERSED_RESOLVE // FIR_IDENTICAL // !DIAGNOSTICS: -FINAL_UPPER_BOUND -CAST_NEVER_SUCCEEDS // !LANGUAGE: +AllowEmptyIntersectionsInResultTypeResolver