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 5a0f7713abb..f389a3fec1d 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 @@ -501,6 +501,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag runTest("compiler/testData/diagnostics/tests/kt54587_2.kt"); } + @Test + @TestMetadata("kt55733.kt") + public void testKt55733() throws Exception { + runTest("compiler/testData/diagnostics/tests/kt55733.kt"); + } + @Test @TestMetadata("LValueAssignment.kt") public void testLValueAssignment() 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 3c79999dd58..c0e57280110 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 @@ -501,6 +501,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti runTest("compiler/testData/diagnostics/tests/kt54587_2.kt"); } + @Test + @TestMetadata("kt55733.kt") + public void testKt55733() throws Exception { + runTest("compiler/testData/diagnostics/tests/kt55733.kt"); + } + @Test @TestMetadata("LValueAssignment.kt") public void testLValueAssignment() 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 3b9e2c52f3e..ea0d8a23a1a 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 @@ -501,6 +501,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac runTest("compiler/testData/diagnostics/tests/kt54587_2.kt"); } + @Test + @TestMetadata("kt55733.kt") + public void testKt55733() throws Exception { + runTest("compiler/testData/diagnostics/tests/kt55733.kt"); + } + @Test @TestMetadata("LValueAssignment.kt") public void testLValueAssignment() throws Exception { diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirStandaloneQualifierChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirStandaloneQualifierChecker.kt index 491bac8e637..4a2b9f317aa 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirStandaloneQualifierChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirStandaloneQualifierChecker.kt @@ -5,14 +5,18 @@ package org.jetbrains.kotlin.fir.analysis.checkers.expression +import org.jetbrains.kotlin.KtSourceElement import org.jetbrains.kotlin.descriptors.ClassKind import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext import org.jetbrains.kotlin.diagnostics.DiagnosticReporter import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors import org.jetbrains.kotlin.diagnostics.reportOn +import org.jetbrains.kotlin.fir.declarations.fullyExpandedClass import org.jetbrains.kotlin.fir.expressions.FirQualifiedAccess import org.jetbrains.kotlin.fir.expressions.FirResolvedQualifier +import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol import org.jetbrains.kotlin.fir.symbols.impl.FirRegularClassSymbol +import org.jetbrains.kotlin.fir.symbols.impl.FirTypeAliasSymbol import org.jetbrains.kotlin.fir.types.isUnit object FirStandaloneQualifierChecker : FirResolvedQualifierChecker() { @@ -23,14 +27,20 @@ object FirStandaloneQualifierChecker : FirResolvedQualifierChecker() { if (lastGetClass?.argument === expression) return // Note: if it's real Unit, it will be filtered by ClassKind.OBJECT check below if (!expression.typeRef.isUnit) return + expression.symbol.reportErrorOn(expression.source, context, reporter) + } - when (val symbol = expression.symbol) { + private fun FirBasedSymbol<*>?.reportErrorOn(source: KtSourceElement?, context: CheckerContext, reporter: DiagnosticReporter) { + when (this) { is FirRegularClassSymbol -> { - if (symbol.classKind == ClassKind.OBJECT) return - reporter.reportOn(expression.source, FirErrors.NO_COMPANION_OBJECT, symbol, context) + if (classKind == ClassKind.OBJECT) return + reporter.reportOn(source, FirErrors.NO_COMPANION_OBJECT, this, context) + } + is FirTypeAliasSymbol -> { + fullyExpandedClass(context.session)?.reportErrorOn(source, context, reporter) } null -> { - reporter.reportOn(expression.source, FirErrors.EXPRESSION_EXPECTED_PACKAGE_FOUND, context) + reporter.reportOn(source, FirErrors.EXPRESSION_EXPECTED_PACKAGE_FOUND, context) } else -> {} } diff --git a/compiler/testData/diagnostics/tests/kt55733.kt b/compiler/testData/diagnostics/tests/kt55733.kt new file mode 100644 index 00000000000..71913f1db06 --- /dev/null +++ b/compiler/testData/diagnostics/tests/kt55733.kt @@ -0,0 +1,7 @@ +// FIR_IDENTICAL + +fun main() { + val appendable = Appendable + val stringBuilder = StringBuilder + val exception = IllegalStateException +} diff --git a/compiler/testData/diagnostics/tests/kt55733.txt b/compiler/testData/diagnostics/tests/kt55733.txt new file mode 100644 index 00000000000..c74813f6f7b --- /dev/null +++ b/compiler/testData/diagnostics/tests/kt55733.txt @@ -0,0 +1,4 @@ +package + +public fun main(): kotlin.Unit + diff --git a/compiler/testData/diagnostics/tests/typealias/throwJLException.fir.kt b/compiler/testData/diagnostics/tests/typealias/throwJLException.fir.kt deleted file mode 100644 index ad99d935b42..00000000000 --- a/compiler/testData/diagnostics/tests/typealias/throwJLException.fir.kt +++ /dev/null @@ -1,7 +0,0 @@ -// +JDK - -typealias Exn = java.lang.Exception - -fun test() { - throw Exn -} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/typealias/throwJLException.kt b/compiler/testData/diagnostics/tests/typealias/throwJLException.kt index 8448c0ad67b..4e5e71ba4f2 100644 --- a/compiler/testData/diagnostics/tests/typealias/throwJLException.kt +++ b/compiler/testData/diagnostics/tests/typealias/throwJLException.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // +JDK typealias Exn = java.lang.Exception diff --git a/compiler/testData/diagnostics/tests/typealias/typeAliasConstructorForInterface.fir.kt b/compiler/testData/diagnostics/tests/typealias/typeAliasConstructorForInterface.fir.kt deleted file mode 100644 index 972debe5f71..00000000000 --- a/compiler/testData/diagnostics/tests/typealias/typeAliasConstructorForInterface.fir.kt +++ /dev/null @@ -1,6 +0,0 @@ -interface IFoo - -typealias Test = IFoo - -val testAsFunction = Test() -val testAsValue = Test diff --git a/compiler/testData/diagnostics/tests/typealias/typeAliasConstructorForInterface.kt b/compiler/testData/diagnostics/tests/typealias/typeAliasConstructorForInterface.kt index 9fb25cbcc02..079edd27166 100644 --- a/compiler/testData/diagnostics/tests/typealias/typeAliasConstructorForInterface.kt +++ b/compiler/testData/diagnostics/tests/typealias/typeAliasConstructorForInterface.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL interface IFoo typealias Test = IFoo 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 bedefef5e81..1a6776a1423 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 @@ -501,6 +501,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/kt54587_2.kt"); } + @Test + @TestMetadata("kt55733.kt") + public void testKt55733() throws Exception { + runTest("compiler/testData/diagnostics/tests/kt55733.kt"); + } + @Test @TestMetadata("LValueAssignment.kt") public void testLValueAssignment() throws Exception {