[FIR] Expand type of const val in FirConstPropertyChecker

This commit is contained in:
Dmitriy Novozhilov
2021-05-21 11:11:08 +03:00
committed by TeamCityServer
parent 669985f853
commit 478a512b24
7 changed files with 32 additions and 2 deletions
@@ -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")
@@ -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|
@@ -0,0 +1,3 @@
typealias Foo = Int
const val x: Foo = 10
@@ -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
@@ -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
@@ -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)
}
}
}
}
@@ -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")