FIR2IR: discard fake overrides for property accessors according to base visibility

This commit is contained in:
Jinseong Jeon
2020-06-30 23:21:47 -07:00
committed by Mikhail Glukhikh
parent 6985c5fd2a
commit 1e3019798a
2 changed files with 14 additions and 10 deletions
@@ -144,6 +144,7 @@ class FakeOverrideGenerator(
)
irProperty.parent = this
result += irProperty.withProperty {
discardAccessorsAccordingToBaseVisibility(baseSymbol)
setOverriddenSymbolsForAccessors(declarationStorage, originalProperty, firOverriddenSymbol = baseSymbol)
}
} else if (fakeOverrideMode != FakeOverrideMode.SUBSTITUTION && originalProperty.allowsToHaveFakeOverrideIn(klass)) {
@@ -160,15 +161,7 @@ class FakeOverrideGenerator(
fakeOverrideProperty, irParent = this,
thisReceiverOwner = declarationStorage.findIrParent(originalProperty) as? IrClass,
origin = origin
).apply {
// Do not create fake overrides for accessors if not allowed to do so, e.g., private lateinit var.
if (baseSymbol.fir.getter?.allowsToHaveFakeOverride != true) {
getter = null
}
if (baseSymbol.fir.setter?.allowsToHaveFakeOverride != true) {
setter = null
}
}
)
if (irProperty.backingField?.type?.containsErrorType() == true ||
irProperty.getter?.returnType?.containsErrorType() == true
) {
@@ -176,6 +169,7 @@ class FakeOverrideGenerator(
}
irProperty.parent = this
result += irProperty.withProperty {
discardAccessorsAccordingToBaseVisibility(baseSymbol)
setOverriddenSymbolsForAccessors(declarationStorage, fakeOverrideProperty, firOverriddenSymbol = baseSymbol)
}
}
@@ -185,6 +179,17 @@ class FakeOverrideGenerator(
return result
}
private fun IrProperty.discardAccessorsAccordingToBaseVisibility(baseSymbol: FirPropertySymbol) {
// Do not create fake overrides for accessors if not allowed to do so, e.g., private lateinit var.
if (baseSymbol.fir.getter?.allowsToHaveFakeOverride != true) {
getter = null
}
// or private setter
if (baseSymbol.fir.setter?.allowsToHaveFakeOverride != true) {
setter = null
}
}
private fun IrProperty.setOverriddenSymbolsForAccessors(
declarationStorage: Fir2IrDeclarationStorage,
property: FirProperty,
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
// FILE: a.kt
package test2