K2: fix implementation of EXTENSION_PROPERTY_MUST_HAVE_ACCESSORS_OR_BE_ABSTRACT

This commit fixes
`FirCompileKotlinAgainstCustomBinariesTest.testUnreachableExtensionVarPropertyDeclaration`.
This commit is contained in:
Mikhail Glukhikh
2023-07-27 20:35:27 +02:00
committed by Space Team
parent 54c7466074
commit 0abf17201f
3 changed files with 7 additions and 5 deletions
@@ -1,5 +1,5 @@
<!MUST_BE_INITIALIZED!>private var Int.readOnlyWrapper: CharSequence?<!> get() = null
<!MUST_BE_INITIALIZED!>private var Int.mutableWrapper: CharSequence?<!> get() = null
<!EXTENSION_PROPERTY_MUST_HAVE_ACCESSORS_OR_BE_ABSTRACT!>private var Int.readOnlyWrapper: CharSequence?<!> get() = null
<!EXTENSION_PROPERTY_MUST_HAVE_ACCESSORS_OR_BE_ABSTRACT!>private var Int.mutableWrapper: CharSequence?<!> get() = null
fun main(x: Int) {
val x = if (x > 1) x::readOnlyWrapper else x::mutableWrapper
@@ -130,7 +130,7 @@ internal fun checkPropertyInitializer(
!isExternal &&
!property.hasExplicitBackingField
) {
if (property.receiverParameter != null && !property.hasAnyAccessorImplementation) {
if (property.receiverParameter != null && !property.hasAllAccessorImplementation) {
reporter.reportOn(propertySource, FirErrors.EXTENSION_PROPERTY_MUST_HAVE_ACCESSORS_OR_BE_ABSTRACT, context)
} else if (reachable) {
reportMustBeInitialized(property, isDefinitelyAssignedInConstructor, containingClass, propertySource, reporter, context)
@@ -209,6 +209,9 @@ private val FirProperty.hasSetterAccessorImplementation: Boolean
private val FirProperty.hasAnyAccessorImplementation: Boolean
get() = getter.hasImplementation || setter.hasImplementation
private val FirProperty.hasAllAccessorImplementation: Boolean
get() = getter.hasImplementation && (isVal || setter.hasImplementation)
private fun FirProperty.getEffectiveModality(containingClass: FirClass?, languageVersionSettings: LanguageVersionSettings): Modality? =
when (languageVersionSettings.supportsFeature(LanguageFeature.TakeIntoAccountEffectivelyFinalInMustBeInitializedCheck) &&
status.modality == Modality.OPEN && containingClass?.status?.modality == Modality.FINAL) {
@@ -663,8 +663,7 @@ abstract class AbstractCompileKotlinAgainstCustomBinariesTest : AbstractKotlinCo
compileKotlin("main.kt", tmpdir, listOf(library), additionalOptions = features)
}
// Fixed in the LV2.0 branch.
fun testUnreachableExtensionVarPropertyDeclaration() = muteForK2 {
fun testUnreachableExtensionVarPropertyDeclaration() {
val (output, exitCode) = compileKotlin("source.kt", tmpdir, expectedFileName = null)
assertEquals("Output:\n$output", ExitCode.COMPILATION_ERROR, exitCode)
}