FIR: Do not add "field" to accessor of a property with receiver

This commit is contained in:
Denis Zharkov
2020-03-17 19:06:55 +03:00
parent ade18d144a
commit a2e7b6d20e
7 changed files with 74 additions and 8 deletions
@@ -205,10 +205,6 @@ abstract class FirAbstractBodyResolveTransformer(phase: FirResolvePhase) : FirAb
updateLastScope { storeVariable(variable) }
}
fun storeBackingField(property: FirProperty) {
updateLastScope { storeBackingField(property) }
}
override fun saveContextForAnonymousFunction(anonymousFunction: FirAnonymousFunction) {
localContextForAnonymousFunctions[anonymousFunction.symbol] = FirLocalContext(localScopes, implicitReceiverStack.snapshot())
}
@@ -114,7 +114,9 @@ class FirDeclarationsResolveTransformer(transformer: FirBodyResolveTransformer)
storeVariableReturnType(property)
}
withLocalScopeCleanup {
addLocalScope(FirLocalScope().storeBackingField(property))
if (property.receiverTypeRef == null) {
addLocalScope(FirLocalScope().storeBackingField(property))
}
property.transformAccessors()
}
}
@@ -0,0 +1,11 @@
interface B {
fun foo(): Int
}
class A {
val String.x: Int get() {
return field.foo()
}
val String.field: B get() = TODO()
}
@@ -0,0 +1,21 @@
FILE: noBackingFieldForExtension.kt
public abstract interface B : R|kotlin/Any| {
public abstract fun foo(): R|kotlin/Int|
}
public final class A : R|kotlin/Any| {
public constructor(): R|A| {
super<R|kotlin/Any|>()
}
public final val R|kotlin/String|.x: R|kotlin/Int|
public get(): R|kotlin/Int| {
^ (this@R|/A|, this@R|/A.x|).R|/A.field|.R|/B.foo|()
}
public final val R|kotlin/String|.field: R|B|
public get(): R|B| {
^ R|kotlin/TODO|()
}
}
@@ -1463,6 +1463,24 @@ public class FirDiagnosticsTestGenerated extends AbstractFirDiagnosticsTest {
}
}
@TestMetadata("compiler/fir/resolve/testData/resolve/properties")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Properties extends AbstractFirDiagnosticsTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
}
public void testAllFilesPresentInProperties() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/resolve/testData/resolve/properties"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
}
@TestMetadata("noBackingFieldForExtension.kt")
public void testNoBackingFieldForExtension() throws Exception {
runTest("compiler/fir/resolve/testData/resolve/properties/noBackingFieldForExtension.kt");
}
}
@TestMetadata("compiler/fir/resolve/testData/resolve/references")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
@@ -1463,6 +1463,24 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
}
}
@TestMetadata("compiler/fir/resolve/testData/resolve/properties")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Properties extends AbstractFirDiagnosticsWithLightTreeTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
}
public void testAllFilesPresentInProperties() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/resolve/testData/resolve/properties"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
}
@TestMetadata("noBackingFieldForExtension.kt")
public void testNoBackingFieldForExtension() throws Exception {
runTest("compiler/fir/resolve/testData/resolve/properties/noBackingFieldForExtension.kt");
}
}
@TestMetadata("compiler/fir/resolve/testData/resolve/references")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
@@ -8,10 +8,10 @@ val String.foo: Int
val String.bar: Int = 13
// Error
get() = field
get() = <!UNRESOLVED_REFERENCE!>field<!>
class My {
val String.x: Int = 7
// Error
get() = field
}
get() = <!UNRESOLVED_REFERENCE!>field<!>
}