diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java index 7817540ce21..4da42e08250 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java @@ -34414,6 +34414,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/throws.kt"); } + @Test + @TestMetadata("throwsByStarWinsBuiltin.kt") + public void testThrowsByStarWinsBuiltin() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/throwsByStarWinsBuiltin.kt"); + } + @Test @TestMetadata("TransientOnDelegate.kt") public void testTransientOnDelegate() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java index d9ef2099ff9..cd8783fad4a 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java @@ -34414,6 +34414,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/throws.kt"); } + @Test + @TestMetadata("throwsByStarWinsBuiltin.kt") + public void testThrowsByStarWinsBuiltin() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/throwsByStarWinsBuiltin.kt"); + } + @Test @TestMetadata("TransientOnDelegate.kt") public void testTransientOnDelegate() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java index 25399c662e6..a23f3be3f7e 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java @@ -34414,6 +34414,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/throws.kt"); } + @Test + @TestMetadata("throwsByStarWinsBuiltin.kt") + public void testThrowsByStarWinsBuiltin() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/throwsByStarWinsBuiltin.kt"); + } + @Test @TestMetadata("TransientOnDelegate.kt") public void testTransientOnDelegate() throws Exception { diff --git a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/DefaultImportPriority.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/DefaultImportPriority.kt index 53995b5807c..cfc9c7e3e9f 100644 --- a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/DefaultImportPriority.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/DefaultImportPriority.kt @@ -16,7 +16,7 @@ enum class DefaultImportPriority { languageVersionSettings: LanguageVersionSettings ): List? = platformDependentAnalyzerServices?.getDefaultImports(languageVersionSettings, includeLowPriorityImports = false)?.let { - it + ImportPath.fromString("kotlin.Throws") + it } }, LOW { @@ -25,6 +25,14 @@ enum class DefaultImportPriority { languageVersionSettings: LanguageVersionSettings ): List? = platformDependentAnalyzerServices?.defaultLowPriorityImports + }, + KOTLIN_THROWS { + override fun getAllDefaultImports( + platformDependentAnalyzerServices: PlatformDependentAnalyzerServices?, + languageVersionSettings: LanguageVersionSettings + ): List { + return listOf(ImportPath.fromString("kotlin.Throws")) + } }; abstract fun getAllDefaultImports( diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/ImportingScopes.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/ImportingScopes.kt index bb9fcfe7866..7b679406994 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/ImportingScopes.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/ImportingScopes.kt @@ -49,6 +49,9 @@ private fun doCreateImportingScopes( scopeSession.getOrBuild(DefaultStarImportKey(DefaultImportPriority.HIGH, excludedImportNames), DEFAULT_STAR_IMPORT) { FirDefaultStarImportingScope(session, scopeSession, DefaultImportPriority.HIGH, excludedImportNames) }, + scopeSession.getOrBuild(DefaultImportPriority.KOTLIN_THROWS, DEFAULT_SIMPLE_IMPORT) { + FirDefaultSimpleImportingScope(session, scopeSession, priority = DefaultImportPriority.KOTLIN_THROWS) + }, FirExplicitStarImportingScope(file.imports, session, scopeSession, excludedImportNames), scopeSession.getOrBuild(DefaultImportPriority.LOW, DEFAULT_SIMPLE_IMPORT) { diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/throws.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/throws.fir.kt index dec5b8282cf..a136fe4032a 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/annotations/throws.fir.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/throws.fir.kt @@ -112,7 +112,7 @@ package abc7 import kotlin.* import kotlin.jvm.* -@Throws(Exception::class) +@Throws(Exception::class) fun foo1() {} @kotlin.Throws(Exception::class) @@ -121,7 +121,7 @@ fun foo2() {} @kotlin.jvm.Throws(Exception::class) fun foo3() {} -fun foo5(x: Throws) {} +fun foo5(x: Throws) {} fun foo6(x: kotlin.Throws) {} fun foo7(x: kotlin.jvm.Throws) {} diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/throwsByStarWinsBuiltin.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/throwsByStarWinsBuiltin.kt new file mode 100644 index 00000000000..1808440903e --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/throwsByStarWinsBuiltin.kt @@ -0,0 +1,19 @@ +// FIR_IDENTICAL +// WITH_STDLIB +// ISSUE: KT-52407 + +// FILE: x.kt + +package x + +class Throws { + fun test() {} +} + +// FILE: main.kt + +import x.* + +fun main() { + Throws().test() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/throwsByStarWinsBuiltin.txt b/compiler/testData/diagnostics/testsWithStdLib/annotations/throwsByStarWinsBuiltin.txt new file mode 100644 index 00000000000..fa5baaa37f7 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/throwsByStarWinsBuiltin.txt @@ -0,0 +1,14 @@ +package + +public fun main(): kotlin.Unit + +package x { + + public final class Throws { + public constructor Throws() + 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 final fun test(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } +} diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java index d3a416cd8f6..d2e41408801 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java @@ -34504,6 +34504,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/throws.kt"); } + @Test + @TestMetadata("throwsByStarWinsBuiltin.kt") + public void testThrowsByStarWinsBuiltin() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/throwsByStarWinsBuiltin.kt"); + } + @Test @TestMetadata("TransientOnDelegate.kt") public void testTransientOnDelegate() throws Exception {