From 478a512b2449d640183ba7b6ac2e5aee5a60f3ae Mon Sep 17 00:00:00 2001 From: Dmitriy Novozhilov Date: Fri, 21 May 2021 11:11:08 +0300 Subject: [PATCH] [FIR] Expand type of const val in FirConstPropertyChecker --- .../LazyBodyIsNotTouchedTilContractsPhaseTestGenerated.java | 5 +++++ .../resolve/constVal/constValWithTypealiasType.fir.txt | 4 ++++ .../testData/resolve/constVal/constValWithTypealiasType.kt | 3 +++ .../kotlin/test/runners/FirDiagnosticTestGenerated.java | 6 ++++++ .../runners/FirDiagnosticsWithLightTreeTestGenerated.java | 6 ++++++ .../checkers/declaration/FirConstPropertyChecker.kt | 5 +++-- .../based/DiagnosisCompilerFirTestdataTestGenerated.java | 5 +++++ 7 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 compiler/fir/analysis-tests/testData/resolve/constVal/constValWithTypealiasType.fir.txt create mode 100644 compiler/fir/analysis-tests/testData/resolve/constVal/constValWithTypealiasType.kt diff --git a/compiler/fir/analysis-tests/legacy-fir-tests/tests-gen/org/jetbrains/kotlin/fir/LazyBodyIsNotTouchedTilContractsPhaseTestGenerated.java b/compiler/fir/analysis-tests/legacy-fir-tests/tests-gen/org/jetbrains/kotlin/fir/LazyBodyIsNotTouchedTilContractsPhaseTestGenerated.java index d87d2352b49..8af97b72d97 100644 --- a/compiler/fir/analysis-tests/legacy-fir-tests/tests-gen/org/jetbrains/kotlin/fir/LazyBodyIsNotTouchedTilContractsPhaseTestGenerated.java +++ b/compiler/fir/analysis-tests/legacy-fir-tests/tests-gen/org/jetbrains/kotlin/fir/LazyBodyIsNotTouchedTilContractsPhaseTestGenerated.java @@ -975,6 +975,11 @@ public class LazyBodyIsNotTouchedTilContractsPhaseTestGenerated extends Abstract public void testConstValWithGetterOrDelegate() throws Exception { runTest("compiler/fir/analysis-tests/testData/resolve/constVal/constValWithGetterOrDelegate.kt"); } + + @TestMetadata("constValWithTypealiasType.kt") + public void testConstValWithTypealiasType() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/constVal/constValWithTypealiasType.kt"); + } } @TestMetadata("compiler/fir/analysis-tests/testData/resolve/constructors") diff --git a/compiler/fir/analysis-tests/testData/resolve/constVal/constValWithTypealiasType.fir.txt b/compiler/fir/analysis-tests/testData/resolve/constVal/constValWithTypealiasType.fir.txt new file mode 100644 index 00000000000..74aa16945af --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolve/constVal/constValWithTypealiasType.fir.txt @@ -0,0 +1,4 @@ +FILE: constValWithTypealiasType.kt + public final typealias Foo = R|kotlin/Int| + public final const val x: R|Foo| = Int(10) + public get(): R|Foo| diff --git a/compiler/fir/analysis-tests/testData/resolve/constVal/constValWithTypealiasType.kt b/compiler/fir/analysis-tests/testData/resolve/constVal/constValWithTypealiasType.kt new file mode 100644 index 00000000000..4c8a08ceb0e --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolve/constVal/constValWithTypealiasType.kt @@ -0,0 +1,3 @@ +typealias Foo = Int + +const val x: Foo = 10 diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticTestGenerated.java index a3316a8ab8f..ccb19648aeb 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticTestGenerated.java @@ -1128,6 +1128,12 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest { public void testConstValWithGetterOrDelegate() throws Exception { runTest("compiler/fir/analysis-tests/testData/resolve/constVal/constValWithGetterOrDelegate.kt"); } + + @Test + @TestMetadata("constValWithTypealiasType.kt") + public void testConstValWithTypealiasType() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/constVal/constValWithTypealiasType.kt"); + } } @Nested diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticsWithLightTreeTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticsWithLightTreeTestGenerated.java index 7b107bab6c0..01bd93f1530 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticsWithLightTreeTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticsWithLightTreeTestGenerated.java @@ -1128,6 +1128,12 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos public void testConstValWithGetterOrDelegate() throws Exception { runTest("compiler/fir/analysis-tests/testData/resolve/constVal/constValWithGetterOrDelegate.kt"); } + + @Test + @TestMetadata("constValWithTypealiasType.kt") + public void testConstValWithTypealiasType() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/constVal/constValWithTypealiasType.kt"); + } } @Nested diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirConstPropertyChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirConstPropertyChecker.kt index 08df9eb4d0a..27cdd050e0a 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirConstPropertyChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirConstPropertyChecker.kt @@ -17,6 +17,7 @@ import org.jetbrains.kotlin.fir.analysis.diagnostics.reportOn import org.jetbrains.kotlin.fir.declarations.FirProperty import org.jetbrains.kotlin.fir.declarations.FirRegularClass import org.jetbrains.kotlin.fir.declarations.isConst +import org.jetbrains.kotlin.fir.resolve.fullyExpandedType import org.jetbrains.kotlin.fir.types.ConeClassErrorType import org.jetbrains.kotlin.fir.types.coneType import org.jetbrains.kotlin.lexer.KtTokens @@ -55,7 +56,7 @@ object FirConstPropertyChecker : FirPropertyChecker() { return } - val type = declaration.returnTypeRef.coneType + val type = declaration.returnTypeRef.coneType.fullyExpandedType(context.session) if ((type !is ConeClassErrorType) && !type.canBeUsedForConstVal()) { reporter.reportOn(declaration.source, FirErrors.TYPE_CANT_BE_USED_FOR_CONST_VAL, declaration.returnTypeRef.coneType, context) return @@ -65,4 +66,4 @@ object FirConstPropertyChecker : FirPropertyChecker() { reporter.reportOn(initializer.source, FirErrors.CONST_VAL_WITH_NON_CONST_INITIALIZER, context) } } -} \ No newline at end of file +} diff --git a/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/diagnostic/compiler/based/DiagnosisCompilerFirTestdataTestGenerated.java b/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/diagnostic/compiler/based/DiagnosisCompilerFirTestdataTestGenerated.java index e9c14c25e84..c88600e1655 100644 --- a/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/diagnostic/compiler/based/DiagnosisCompilerFirTestdataTestGenerated.java +++ b/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/diagnostic/compiler/based/DiagnosisCompilerFirTestdataTestGenerated.java @@ -977,6 +977,11 @@ public class DiagnosisCompilerFirTestdataTestGenerated extends AbstractDiagnosis public void testConstValWithGetterOrDelegate() throws Exception { runTest("compiler/fir/analysis-tests/testData/resolve/constVal/constValWithGetterOrDelegate.kt"); } + + @TestMetadata("constValWithTypealiasType.kt") + public void testConstValWithTypealiasType() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/constVal/constValWithTypealiasType.kt"); + } } @TestMetadata("compiler/fir/analysis-tests/testData/resolve/constructors")