FIR: unwrap f/overrides when determining mutability of property reference

#KT-44010 Fixed
This commit is contained in:
Jinseong Jeon
2020-12-21 12:51:59 -08:00
committed by Mikhail Glukhikh
parent 0918e73dff
commit 78fa8814c4
5 changed files with 111 additions and 2 deletions
@@ -3004,6 +3004,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
runTest("compiler/testData/diagnostics/tests/callableReference/property/memberFromTopLevel.kt");
}
@Test
@TestMetadata("propertyFromAbstractSuperClass.kt")
public void testPropertyFromAbstractSuperClass() throws Exception {
runTest("compiler/testData/diagnostics/tests/callableReference/property/propertyFromAbstractSuperClass.kt");
}
@Test
@TestMetadata("protectedVarFromClass.kt")
public void testProtectedVarFromClass() throws Exception {
@@ -401,6 +401,8 @@ private fun createKPropertyType(
private fun FirVariable<*>.canBeMutableReference(candidate: Candidate): Boolean {
if (!isVar) return false
if (this is FirField) return true
return source?.kind == FirFakeSourceElementKind.PropertyFromParameter ||
(setter is FirMemberDeclaration && candidate.callInfo.session.visibilityChecker.isVisible(setter!!, candidate))
val original = this.unwrapFakeOverrides()
return original.source?.kind == FirFakeSourceElementKind.PropertyFromParameter ||
(original.setter is FirMemberDeclaration &&
candidate.callInfo.session.visibilityChecker.isVisible(original.setter!!, candidate))
}
@@ -0,0 +1,36 @@
// FIR_IDENTICAL
import kotlin.reflect.KMutableProperty0
class Module
class Context
class Model(
private val value: KMutableProperty0<Module>,
private val context: Context
)
abstract class Reference<V : Any> {
abstract var v : V
}
class ModuleReference(m : Module) : Reference<Module>() {
override var v : Module = m
}
abstract class SettingComponent<V: Any>(
val reference: Reference<V>
) {
var value: V
get() = reference.v
set(value) {
reference.v = value
}
}
class Component(
reference: Reference<Module>,
context: Context
) : SettingComponent<Module>(reference) {
private val model = Model(::value, context)
}
@@ -0,0 +1,59 @@
package
public final class Component : SettingComponent<Module> {
public constructor Component(/*0*/ reference: Reference<Module>, /*1*/ context: Context)
private final val model: Model
public final override /*1*/ /*fake_override*/ val reference: Reference<Module>
public final override /*1*/ /*fake_override*/ var value: Module
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public final class Context {
public constructor Context()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public final class Model {
public constructor Model(/*0*/ value: kotlin.reflect.KMutableProperty0<Module>, /*1*/ context: Context)
private final val context: Context
private final val value: kotlin.reflect.KMutableProperty0<Module>
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public final class Module {
public constructor Module()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public final class ModuleReference : Reference<Module> {
public constructor ModuleReference(/*0*/ m: Module)
public open override /*1*/ var v: Module
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public abstract class Reference</*0*/ V : kotlin.Any> {
public constructor Reference</*0*/ V : kotlin.Any>()
public abstract var v: V
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public abstract class SettingComponent</*0*/ V : kotlin.Any> {
public constructor SettingComponent</*0*/ V : kotlin.Any>(/*0*/ reference: Reference<V>)
public final val reference: Reference<V>
public final var value: V
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -3010,6 +3010,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
runTest("compiler/testData/diagnostics/tests/callableReference/property/memberFromTopLevel.kt");
}
@Test
@TestMetadata("propertyFromAbstractSuperClass.kt")
public void testPropertyFromAbstractSuperClass() throws Exception {
runTest("compiler/testData/diagnostics/tests/callableReference/property/propertyFromAbstractSuperClass.kt");
}
@Test
@TestMetadata("protectedVarFromClass.kt")
public void testProtectedVarFromClass() throws Exception {