From 8bd792792f257f55afdd7078a520e89cd3d45864 Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Thu, 28 Sep 2023 11:42:53 +0200 Subject: [PATCH] K2: consider backing fields of vars as smartcast unstable #KT-61974 Fixed --- .../jetbrains/kotlin/fir/resolve/dfa/VariableStorageImpl.kt | 5 ++--- .../firProblems/elvisOnBackingFieldInGetter.fir.ir.txt | 6 +++--- .../firProblems/elvisOnBackingFieldInGetter.fir.kt.txt | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/dfa/VariableStorageImpl.kt b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/dfa/VariableStorageImpl.kt index e627cc7c05e..7baa6efecca 100644 --- a/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/dfa/VariableStorageImpl.kt +++ b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/dfa/VariableStorageImpl.kt @@ -161,9 +161,8 @@ class VariableStorageImpl(private val session: FirSession) : VariableStorage() { if (originalFir is FirThisReceiverExpression) return PropertyStability.STABLE_VALUE when (this) { is FirAnonymousObjectSymbol -> return null - is FirFunctionSymbol<*>, - is FirClassSymbol<*>, - is FirBackingFieldSymbol -> return PropertyStability.STABLE_VALUE + is FirFunctionSymbol<*>, is FirClassSymbol<*> -> return PropertyStability.STABLE_VALUE + is FirBackingFieldSymbol -> return if (isVal) PropertyStability.STABLE_VALUE else PropertyStability.MUTABLE_PROPERTY } if (this !is FirVariableSymbol<*>) return null if (this is FirFieldSymbol && !this.isFinal) return PropertyStability.MUTABLE_PROPERTY diff --git a/compiler/testData/ir/irText/firProblems/elvisOnBackingFieldInGetter.fir.ir.txt b/compiler/testData/ir/irText/firProblems/elvisOnBackingFieldInGetter.fir.ir.txt index 14274ae000a..66bd8b12f31 100644 --- a/compiler/testData/ir/irText/firProblems/elvisOnBackingFieldInGetter.fir.ir.txt +++ b/compiler/testData/ir/irText/firProblems/elvisOnBackingFieldInGetter.fir.ir.txt @@ -39,18 +39,18 @@ FILE fqName: fileName:/elvisOnBackingFieldInGetter.kt value: CONSTRUCTOR_CALL 'public constructor () declared in .ResourceTable' type=.ResourceTable origin=null RETURN type=kotlin.Nothing from='public final fun (): .ResourceTable? declared in .Test' BLOCK type=.ResourceTable origin=ELVIS - VAR IR_TEMPORARY_VARIABLE name:tmp_0 type:kotlin.Nothing? [val] + VAR IR_TEMPORARY_VARIABLE name:tmp_0 type:.ResourceTable? [val] GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:resourceTable type:.ResourceTable? visibility:private' type=.ResourceTable? origin=GET_PROPERTY receiver: GET_VAR ': .Test declared in .Test.' type=.Test origin=null WHEN type=.ResourceTable origin=null BRANCH if: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ - arg0: GET_VAR 'val tmp_0: kotlin.Nothing? declared in .Test.' type=kotlin.Nothing? origin=null + arg0: GET_VAR 'val tmp_0: .ResourceTable? declared in .Test.' type=.ResourceTable? origin=null arg1: CONST Null type=kotlin.Nothing? value=null then: CONSTRUCTOR_CALL 'public constructor () declared in .ResourceTable' type=.ResourceTable origin=null BRANCH if: CONST Boolean type=kotlin.Boolean value=true - then: GET_VAR 'val tmp_0: kotlin.Nothing? declared in .Test.' type=kotlin.Nothing? origin=null + then: GET_VAR 'val tmp_0: .ResourceTable? declared in .Test.' type=.ResourceTable? origin=null FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> ($this:.Test, :.ResourceTable?) returnType:kotlin.Unit correspondingProperty: PROPERTY name:resourceTable visibility:public modality:FINAL [var] $this: VALUE_PARAMETER name: type:.Test diff --git a/compiler/testData/ir/irText/firProblems/elvisOnBackingFieldInGetter.fir.kt.txt b/compiler/testData/ir/irText/firProblems/elvisOnBackingFieldInGetter.fir.kt.txt index f93e6cf08a4..81366e83387 100644 --- a/compiler/testData/ir/irText/firProblems/elvisOnBackingFieldInGetter.fir.kt.txt +++ b/compiler/testData/ir/irText/firProblems/elvisOnBackingFieldInGetter.fir.kt.txt @@ -20,7 +20,7 @@ class Test { } } return { // BLOCK - val : Nothing? = .#resourceTable + val : ResourceTable? = .#resourceTable when { EQEQ(arg0 = , arg1 = null) -> ResourceTable() else ->