diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java index f041d0db6f0..03c7afd57ff 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java @@ -6910,6 +6910,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/interfaceDelegationAndBridgesProcessing.kt"); } + @Test + @TestMetadata("internalLeakBug.kt") + public void testInternalLeakBug() throws Exception { + runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/internalLeakBug.kt"); + } + @Test @TestMetadata("internalSetterOverridden.kt") public void testInternalSetterOverridden() throws Exception { diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/LazyImportScope.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/LazyImportScope.kt index 21e13c0be9b..838670a9725 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/LazyImportScope.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/LazyImportScope.kt @@ -21,6 +21,7 @@ import com.google.common.collect.ImmutableListMultimap import com.google.common.collect.ListMultimap import gnu.trove.THashSet import org.jetbrains.kotlin.builtins.PlatformToKotlinClassMapper +import org.jetbrains.kotlin.config.LanguageFeature import org.jetbrains.kotlin.config.LanguageVersionSettings import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.DescriptorVisibilityUtils.isVisibleIgnoringReceiver @@ -241,7 +242,15 @@ class LazyImportScope( val visibility = (descriptor as DeclarationDescriptorWithVisibility).visibility val includeVisible = filteringKind == FilteringKind.VISIBLE_CLASSES if (!visibility.mustCheckInImports()) return includeVisible - return isVisibleIgnoringReceiver(descriptor, components.moduleDescriptor, components.languageVersionSettings) == includeVisible + val fromDescriptor = + if (components.languageVersionSettings.supportsFeature(LanguageFeature.ProperInternalVisibilityCheckInImportingScope)) { + packageFragment ?: components.moduleDescriptor + } else { + components.moduleDescriptor + } + return isVisibleIgnoringReceiver( + descriptor, fromDescriptor, components.languageVersionSettings + ) == includeVisible } override fun getContributedClassifier(name: Name, location: LookupLocation): ClassifierDescriptor? { diff --git a/compiler/testData/codegen/box/compileKotlinAgainstKotlin/internalLeakBug.kt b/compiler/testData/codegen/box/compileKotlinAgainstKotlin/internalLeakBug.kt new file mode 100644 index 00000000000..56d5a9af905 --- /dev/null +++ b/compiler/testData/codegen/box/compileKotlinAgainstKotlin/internalLeakBug.kt @@ -0,0 +1,25 @@ +// TARGET_BACKEND: JVM +// !LANGUAGE: +ProperInternalVisibilityCheckInImportingScope +// See also: KT-23727 +// WITH_STDLIB +// MODULE: m1 +// FILE: Foo.kt + +package foo + +internal annotation class Volatile + +// MODULE: m2(m1) +// FILE: Bar.kt + +import foo.* + +class Bar { + @Volatile + var v = 0 +} + +fun box(): String { + val bar = Bar() + return if (bar.v == 0) "OK" else "FAIL: ${bar.v}" +} diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java index a60948b58f0..fee7cc2c6d4 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java @@ -6838,6 +6838,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/interfaceDelegationAndBridgesProcessing.kt"); } + @Test + @TestMetadata("internalLeakBug.kt") + public void testInternalLeakBug() throws Exception { + runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/internalLeakBug.kt"); + } + @Test @TestMetadata("internalSetterOverridden.kt") public void testInternalSetterOverridden() throws Exception { diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java index 69302e5b6cb..812d9df9bfd 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java @@ -6910,6 +6910,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/interfaceDelegationAndBridgesProcessing.kt"); } + @Test + @TestMetadata("internalLeakBug.kt") + public void testInternalLeakBug() throws Exception { + runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/internalLeakBug.kt"); + } + @Test @TestMetadata("internalSetterOverridden.kt") public void testInternalSetterOverridden() throws Exception { diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/JvmIrAgainstOldBoxTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/JvmIrAgainstOldBoxTestGenerated.java index 448986a6689..dd2273a13bc 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/JvmIrAgainstOldBoxTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/JvmIrAgainstOldBoxTestGenerated.java @@ -187,6 +187,12 @@ public class JvmIrAgainstOldBoxTestGenerated extends AbstractJvmIrAgainstOldBoxT runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/interfaceDelegationAndBridgesProcessing.kt"); } + @Test + @TestMetadata("internalLeakBug.kt") + public void testInternalLeakBug() throws Exception { + runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/internalLeakBug.kt"); + } + @Test @TestMetadata("internalSetterOverridden.kt") public void testInternalSetterOverridden() throws Exception { diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/JvmOldAgainstIrBoxTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/JvmOldAgainstIrBoxTestGenerated.java index 0c93afd4694..1c0f520599a 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/JvmOldAgainstIrBoxTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/JvmOldAgainstIrBoxTestGenerated.java @@ -187,6 +187,12 @@ public class JvmOldAgainstIrBoxTestGenerated extends AbstractJvmOldAgainstIrBoxT runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/interfaceDelegationAndBridgesProcessing.kt"); } + @Test + @TestMetadata("internalLeakBug.kt") + public void testInternalLeakBug() throws Exception { + runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/internalLeakBug.kt"); + } + @Test @TestMetadata("internalSetterOverridden.kt") public void testInternalSetterOverridden() throws Exception { diff --git a/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt b/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt index 033cc833719..613ca5ba81d 100644 --- a/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt +++ b/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt @@ -242,6 +242,7 @@ enum class LanguageFeature( EliminateAmbiguitiesWithExternalTypeParameters(KOTLIN_1_7), EliminateAmbiguitiesOnInheritedSamInterfaces(KOTLIN_1_7), ConsiderExtensionReceiverFromConstrainsInLambda(KOTLIN_1_7, kind = BUG_FIX), // KT-49832 + ProperInternalVisibilityCheckInImportingScope(KOTLIN_1_7, kind = BUG_FIX), // 1.8 diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeExtBlackBoxTestGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeExtBlackBoxTestGenerated.java index 706c431e414..ae4aef197ae 100644 --- a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeExtBlackBoxTestGenerated.java +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeExtBlackBoxTestGenerated.java @@ -6987,6 +6987,12 @@ public class NativeExtBlackBoxTestGenerated extends AbstractNativeBlackBoxTest { runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/interfaceDelegationAndBridgesProcessing.kt"); } + @Test + @TestMetadata("internalLeakBug.kt") + public void testInternalLeakBug() throws Exception { + runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/internalLeakBug.kt"); + } + @Test @TestMetadata("internalSetterOverridden.kt") public void testInternalSetterOverridden() throws Exception {