Skip to content

Commit 63e4c5b

Browse files
mglukhikhSpace Team
authored andcommitted
K2: drop unclear field.initializerResolved check for delegate fields & enums
The property FirVariable.initializerResolved had two problems: in fact, it was 'initializerHasResolvedType' with no guarantees that the WHOLE initializer was resolved, and additional check on error expression making the semantics quite unclear. With return or comparison expressions as initializer (maybe other cases were possible) this provoked an exception from KT-82466 as such kind of expression has resolved type from the beginning (e.g. Nothing) and their children could remain unresolved for delegate fields. In this commit I dropped the questionable initializerResolved checks for delegate fields & enum entries. Both places don't influence our tests and possible performance impact is also questionable because of 'if (implicitTypeOnly)' check before. #KT-82466 Fixed
1 parent 1a571af commit 63e4c5b

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
lines changed

compiler/fir/analysis-tests/testData/resolve/checkers/delegationWithReturn.fir.fail

Whitespace-only changes.

compiler/fir/analysis-tests/testData/resolve/checkers/delegationWithReturn.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,9 @@
44
interface Base
55
class Derived: Base
66

7-
class C(val k: Derived): Base by return k
7+
class C(val k: Derived): Base by <!RETURN_NOT_ALLOWED!>return<!> k
8+
9+
class D(val k: Derived): Base by <!TYPE_MISMATCH!>k <!UNRESOLVED_REFERENCE!><<!> <!RETURN_NOT_ALLOWED!>return<!> k<!>
10+
11+
/* GENERATED_FIR_TAGS: classDeclaration, inheritanceDelegation, interfaceDeclaration, primaryConstructor,
12+
propertyDeclaration */

compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirDeclarationsResolveTransformer.kt

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ import org.jetbrains.kotlin.fir.symbols.impl.FirValueParameterSymbol
5454
import org.jetbrains.kotlin.fir.types.*
5555
import org.jetbrains.kotlin.fir.types.builder.buildErrorTypeRef
5656
import org.jetbrains.kotlin.fir.types.builder.buildResolvedTypeRef
57+
import org.jetbrains.kotlin.fir.types.hasResolvedType
5758
import org.jetbrains.kotlin.fir.utils.exceptions.withFirEntry
5859
import org.jetbrains.kotlin.fir.visitors.FirTransformer
5960
import org.jetbrains.kotlin.fir.visitors.transformSingle
@@ -120,7 +121,7 @@ open class FirDeclarationsResolveTransformer(
120121
}
121122

122123
override fun transformEnumEntry(enumEntry: FirEnumEntry, data: ResolutionMode): FirEnumEntry {
123-
if (implicitTypeOnly || enumEntry.initializerResolved) return enumEntry
124+
if (implicitTypeOnly) return enumEntry
124125
return context.withEnumEntry(enumEntry) {
125126
(enumEntry.transformChildren(this, data) as FirEnumEntry)
126127
}
@@ -301,7 +302,6 @@ open class FirDeclarationsResolveTransformer(
301302
override fun transformField(field: FirField, data: ResolutionMode): FirField = whileAnalysing(session, field) {
302303
val returnTypeRef = field.returnTypeRef
303304
if (implicitTypeOnly) return field
304-
if (field.initializerResolved) return field
305305

306306
dataFlowAnalyzer.enterField(field)
307307
return withFullBodyResolve {
@@ -1638,12 +1638,6 @@ open class FirDeclarationsResolveTransformer(
16381638
}
16391639

16401640

1641-
private val FirVariable.initializerResolved: Boolean
1642-
get() {
1643-
val initializer = initializer ?: return false
1644-
return initializer.hasResolvedType && initializer !is FirErrorExpression
1645-
}
1646-
16471641
private val FirFunction.bodyResolved: Boolean
16481642
get() = body?.hasResolvedType == true
16491643
}

0 commit comments

Comments
 (0)