From 756cd25417e71041e7720424ce3255b36fe18759 Mon Sep 17 00:00:00 2001 From: "Evgeniy.Zhelenskiy" Date: Fri, 27 Oct 2023 14:48:29 +0200 Subject: [PATCH] [FIR] Support typed projections in exposed visibility declaration checker #KT-62925 --- .../FirExposedVisibilityDeclarationChecker.kt | 2 +- .../diagnostics/tests/exposed/typeArgs.fir.kt | 18 +++++++++++++ .../diagnostics/tests/exposed/typeArgs.kt | 20 ++++++++++++++- .../diagnostics/tests/exposed/typeArgs.txt | 25 +++++++++++++++++++ 4 files changed, 63 insertions(+), 2 deletions(-) diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirExposedVisibilityDeclarationChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirExposedVisibilityDeclarationChecker.kt index 87d8fb40597..7e06a842139 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirExposedVisibilityDeclarationChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirExposedVisibilityDeclarationChecker.kt @@ -250,11 +250,11 @@ object FirExposedVisibilityDeclarationChecker : FirBasicDeclarationChecker() { for ((index, it) in type.typeArguments.withIndex()) { when (it) { is ConeClassLikeType -> it.findVisibilityExposure(context, base, visitedTypes)?.let { return it } + is ConeKotlinTypeProjection -> it.type.findVisibilityExposure(context, base, visitedTypes)?.let { return it } is ConeStarProjection -> type.toRegularClassSymbol(context.session) ?.typeParameterSymbols?.getOrNull(index) ?.resolvedBounds?.firstNotNullOfOrNull { it.type.findVisibilityExposure(context, base, visitedTypes) } ?.let { return it } - else -> {} } } diff --git a/compiler/testData/diagnostics/tests/exposed/typeArgs.fir.kt b/compiler/testData/diagnostics/tests/exposed/typeArgs.fir.kt index 8831e61198c..3933d207d25 100644 --- a/compiler/testData/diagnostics/tests/exposed/typeArgs.fir.kt +++ b/compiler/testData/diagnostics/tests/exposed/typeArgs.fir.kt @@ -15,3 +15,21 @@ interface Our { // invalid, Generic is effectively internal fun foo(): Generic<*> } + +// MODULE: a + +internal interface Inter { + fun foo() = 10 +} + +class Wrapper(val it: T) + +fun public(a: T & Any) = Wrapper(a) + +fun other() = public(object : Inter {}) + +// MODULE: b(a) + +fun test() { + other().it.foo() // ok in K1, invisible reference in K2 +} diff --git a/compiler/testData/diagnostics/tests/exposed/typeArgs.kt b/compiler/testData/diagnostics/tests/exposed/typeArgs.kt index df59edbf9d4..bd3d3950b06 100644 --- a/compiler/testData/diagnostics/tests/exposed/typeArgs.kt +++ b/compiler/testData/diagnostics/tests/exposed/typeArgs.kt @@ -14,4 +14,22 @@ interface Generic<E: My> interface Our { // invalid, Generic is effectively internal fun foo(): Generic<*> -} \ No newline at end of file +} + +// MODULE: a + +internal interface Inter { + fun foo() = 10 +} + +class Wrapper(val it: T) + +fun public(a: T & Any) = Wrapper(a) + +fun other() = public(object : Inter {}) + +// MODULE: b(a) + +fun test() { + other().it.foo() // ok in K1, invisible reference in K2 +} diff --git a/compiler/testData/diagnostics/tests/exposed/typeArgs.txt b/compiler/testData/diagnostics/tests/exposed/typeArgs.txt index 9d8a8c27238..23332fec48d 100644 --- a/compiler/testData/diagnostics/tests/exposed/typeArgs.txt +++ b/compiler/testData/diagnostics/tests/exposed/typeArgs.txt @@ -1,5 +1,9 @@ +// -- Module: -- package +public fun other(): Wrapper`> +public fun public(/*0*/ a: T & Any): Wrapper + public interface Generic { public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int @@ -23,6 +27,13 @@ public interface His : kotlin.collections.List { public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String } +internal interface Inter { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open fun foo(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + internal open class My { public constructor My() public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean @@ -37,6 +48,14 @@ public interface Our { public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String } +public final class Wrapper { + public constructor Wrapper(/*0*/ it: T) + public final val it: T + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + public abstract class Your { public constructor Your() public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean @@ -44,3 +63,9 @@ public abstract class Your { public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String } + +// -- Module: -- +package + +public fun test(): kotlin.Unit +