From 060f3fa7c41070d70fdd3824274f2f0e318c7d10 Mon Sep 17 00:00:00 2001 From: Mikhail Zarechenskiy Date: Wed, 7 Jun 2023 15:40:05 +0200 Subject: [PATCH] Extract diagnostics about class literals with empty LHS ^KT-59152 --- ...icCompilerTestFE10TestdataTestGenerated.java | 6 ++++++ ...nosticCompilerFE10TestDataTestGenerated.java | 6 ++++++ ...TreeOldFrontendDiagnosticsTestGenerated.java | 6 ++++++ ...rPsiOldFrontendDiagnosticsTestGenerated.java | 6 ++++++ .../jetbrains/kotlin/diagnostics/Errors.java | 1 + .../rendering/DefaultErrorMessages.java | 1 + .../DoubleColonExpressionResolver.kt | 2 +- .../classLiteralsWithEmptyLHS.fir.kt | 17 +++++++++++++++++ .../unsupported/classLiteralsWithEmptyLHS.kt | 17 +++++++++++++++++ .../test/runners/DiagnosticTestGenerated.java | 6 ++++++ 10 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 compiler/testData/diagnostics/tests/callableReference/unsupported/classLiteralsWithEmptyLHS.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/unsupported/classLiteralsWithEmptyLHS.kt diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java index d76770d1b2b..6f4cefc5bb9 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java @@ -4579,6 +4579,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia runTest("compiler/testData/diagnostics/tests/callableReference/unsupported/callableReferenceToLocalVariable.kt"); } + @Test + @TestMetadata("classLiteralsWithEmptyLHS.kt") + public void testClassLiteralsWithEmptyLHS() throws Exception { + runTest("compiler/testData/diagnostics/tests/callableReference/unsupported/classLiteralsWithEmptyLHS.kt"); + } + @Test @TestMetadata("javaOverridesKotlinProperty.kt") public void testJavaOverridesKotlinProperty() throws Exception { diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java index bea3a833e95..8b2b2830413 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java @@ -4579,6 +4579,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated runTest("compiler/testData/diagnostics/tests/callableReference/unsupported/callableReferenceToLocalVariable.kt"); } + @Test + @TestMetadata("classLiteralsWithEmptyLHS.kt") + public void testClassLiteralsWithEmptyLHS() throws Exception { + runTest("compiler/testData/diagnostics/tests/callableReference/unsupported/classLiteralsWithEmptyLHS.kt"); + } + @Test @TestMetadata("javaOverridesKotlinProperty.kt") public void testJavaOverridesKotlinProperty() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java index 5ab6d5c4fe3..bd88cbf59ed 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java @@ -4579,6 +4579,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir runTest("compiler/testData/diagnostics/tests/callableReference/unsupported/callableReferenceToLocalVariable.kt"); } + @Test + @TestMetadata("classLiteralsWithEmptyLHS.kt") + public void testClassLiteralsWithEmptyLHS() throws Exception { + runTest("compiler/testData/diagnostics/tests/callableReference/unsupported/classLiteralsWithEmptyLHS.kt"); + } + @Test @TestMetadata("javaOverridesKotlinProperty.kt") public void testJavaOverridesKotlinProperty() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java index a5d25fc1f4e..7ff44606559 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java @@ -4585,6 +4585,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia runTest("compiler/testData/diagnostics/tests/callableReference/unsupported/callableReferenceToLocalVariable.kt"); } + @Test + @TestMetadata("classLiteralsWithEmptyLHS.kt") + public void testClassLiteralsWithEmptyLHS() throws Exception { + runTest("compiler/testData/diagnostics/tests/callableReference/unsupported/classLiteralsWithEmptyLHS.kt"); + } + @Test @TestMetadata("javaOverridesKotlinProperty.kt") public void testJavaOverridesKotlinProperty() throws Exception { diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java index 6038b860a50..a65c8aa180a 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java @@ -82,6 +82,7 @@ public interface Errors { DiagnosticFactory0 UNSUPPORTED_SEALED_FUN_INTERFACE = DiagnosticFactory0.create(ERROR); DiagnosticFactory0 UNSUPPORTED_SUSPEND_TEST = DiagnosticFactory0.create(ERROR); DiagnosticFactory0 UNSUPPORTED_REFERENCES_TO_VARIABLES_AND_PARAMETERS = DiagnosticFactory0.create(ERROR); + DiagnosticFactory0 UNSUPPORTED_CLASS_LITERALS_WITH_EMPTY_LHS = DiagnosticFactory0.create(ERROR); //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java index daf83e01a7d..b03427770ff 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java @@ -830,6 +830,7 @@ public class DefaultErrorMessages { MAP.put(UNSUPPORTED_SEALED_FUN_INTERFACE, "'sealed fun interface' is unsupported"); MAP.put(UNSUPPORTED_SUSPEND_TEST, "'suspend' functions annotated with @kotlin.test.Test are unsupported"); MAP.put(UNSUPPORTED_REFERENCES_TO_VARIABLES_AND_PARAMETERS, "References to variables and parameters are unsupported"); + MAP.put(UNSUPPORTED_CLASS_LITERALS_WITH_EMPTY_LHS, "Class literals with empty left hand side are unsupported"); MAP.put(EXCEPTION_FROM_ANALYZER, "Internal Error occurred while analyzing this expression:\n{0}", THROWABLE); MAP.put(MISSING_STDLIB, "{0}. Ensure you have the standard Kotlin library in dependencies", STRING); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/DoubleColonExpressionResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/DoubleColonExpressionResolver.kt index 3fb1d1624eb..c7d29c1404b 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/DoubleColonExpressionResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/DoubleColonExpressionResolver.kt @@ -106,7 +106,7 @@ class DoubleColonExpressionResolver( fun visitClassLiteralExpression(expression: KtClassLiteralExpression, c: ExpressionTypingContext): KotlinTypeInfo { if (expression.isEmptyLHS) { // "::class" will maybe mean "this::class", a class of "this" instance - c.trace.report(UNSUPPORTED.on(expression, "Class literals with empty left hand side are not yet supported")) + c.trace.report(UNSUPPORTED_CLASS_LITERALS_WITH_EMPTY_LHS.on(expression)) } else { val result = resolveDoubleColonLHS(expression, c) diff --git a/compiler/testData/diagnostics/tests/callableReference/unsupported/classLiteralsWithEmptyLHS.fir.kt b/compiler/testData/diagnostics/tests/callableReference/unsupported/classLiteralsWithEmptyLHS.fir.kt new file mode 100644 index 00000000000..8b6132d8fdf --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/unsupported/classLiteralsWithEmptyLHS.fir.kt @@ -0,0 +1,17 @@ +fun regular() { + ::class + + with(Any()) { + ::class + } +} + +fun Any.extension() { + ::class +} + +class A { + fun member() { + ::class + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/callableReference/unsupported/classLiteralsWithEmptyLHS.kt b/compiler/testData/diagnostics/tests/callableReference/unsupported/classLiteralsWithEmptyLHS.kt new file mode 100644 index 00000000000..5e8e98039bc --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/unsupported/classLiteralsWithEmptyLHS.kt @@ -0,0 +1,17 @@ +fun regular() { + ::class + + with(Any()) { + ::class + } +} + +fun Any.extension() { + ::class +} + +class A { + fun member() { + ::class + } +} \ No newline at end of file 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 45b6db18a89..60b44a87ca5 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 @@ -4585,6 +4585,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/callableReference/unsupported/callableReferenceToLocalVariable.kt"); } + @Test + @TestMetadata("classLiteralsWithEmptyLHS.kt") + public void testClassLiteralsWithEmptyLHS() throws Exception { + runTest("compiler/testData/diagnostics/tests/callableReference/unsupported/classLiteralsWithEmptyLHS.kt"); + } + @Test @TestMetadata("javaOverridesKotlinProperty.kt") public void testJavaOverridesKotlinProperty() throws Exception {