FIR: Do not add "field" to accessor of a property with receiver
This commit is contained in:
-4
@@ -205,10 +205,6 @@ abstract class FirAbstractBodyResolveTransformer(phase: FirResolvePhase) : FirAb
|
|||||||
updateLastScope { storeVariable(variable) }
|
updateLastScope { storeVariable(variable) }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun storeBackingField(property: FirProperty) {
|
|
||||||
updateLastScope { storeBackingField(property) }
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun saveContextForAnonymousFunction(anonymousFunction: FirAnonymousFunction) {
|
override fun saveContextForAnonymousFunction(anonymousFunction: FirAnonymousFunction) {
|
||||||
localContextForAnonymousFunctions[anonymousFunction.symbol] = FirLocalContext(localScopes, implicitReceiverStack.snapshot())
|
localContextForAnonymousFunctions[anonymousFunction.symbol] = FirLocalContext(localScopes, implicitReceiverStack.snapshot())
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-1
@@ -114,7 +114,9 @@ class FirDeclarationsResolveTransformer(transformer: FirBodyResolveTransformer)
|
|||||||
storeVariableReturnType(property)
|
storeVariableReturnType(property)
|
||||||
}
|
}
|
||||||
withLocalScopeCleanup {
|
withLocalScopeCleanup {
|
||||||
addLocalScope(FirLocalScope().storeBackingField(property))
|
if (property.receiverTypeRef == null) {
|
||||||
|
addLocalScope(FirLocalScope().storeBackingField(property))
|
||||||
|
}
|
||||||
property.transformAccessors()
|
property.transformAccessors()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+11
@@ -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()
|
||||||
|
}
|
||||||
+21
@@ -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|()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+18
@@ -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")
|
@TestMetadata("compiler/fir/resolve/testData/resolve/references")
|
||||||
@TestDataPath("$PROJECT_ROOT")
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
@RunWith(JUnit3RunnerWithInners.class)
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
|||||||
Generated
+18
@@ -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")
|
@TestMetadata("compiler/fir/resolve/testData/resolve/references")
|
||||||
@TestDataPath("$PROJECT_ROOT")
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
@RunWith(JUnit3RunnerWithInners.class)
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
|||||||
@@ -8,10 +8,10 @@ val String.foo: Int
|
|||||||
|
|
||||||
val String.bar: Int = 13
|
val String.bar: Int = 13
|
||||||
// Error
|
// Error
|
||||||
get() = field
|
get() = <!UNRESOLVED_REFERENCE!>field<!>
|
||||||
|
|
||||||
class My {
|
class My {
|
||||||
val String.x: Int = 7
|
val String.x: Int = 7
|
||||||
// Error
|
// Error
|
||||||
get() = field
|
get() = <!UNRESOLVED_REFERENCE!>field<!>
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user