[FIR] Don't create backing field for property without explicit type
#KT-41977 Fixed
This commit is contained in:
+15
@@ -0,0 +1,15 @@
|
||||
// ISSUE: KT-41977
|
||||
|
||||
class A {
|
||||
val field: String = "" // (1)
|
||||
|
||||
val x
|
||||
get() = field.length // should be ok, resolve to (1)
|
||||
}
|
||||
|
||||
class B {
|
||||
val field: String = ""
|
||||
|
||||
val x: Int
|
||||
get() = field.<!UNRESOLVED_REFERENCE!>length<!> // should be an error
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
FILE: noBackingFieldInProperty.kt
|
||||
public final class A : R|kotlin/Any| {
|
||||
public constructor(): R|A| {
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
|
||||
public final val field: R|kotlin/String| = String()
|
||||
public get(): R|kotlin/String|
|
||||
|
||||
public final val x: R|kotlin/Int|
|
||||
public get(): R|kotlin/Int| {
|
||||
^ this@R|/A|.R|/A.field|.R|kotlin/String.length|
|
||||
}
|
||||
|
||||
}
|
||||
public final class B : R|kotlin/Any| {
|
||||
public constructor(): R|B| {
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
|
||||
public final val field: R|kotlin/String| = String()
|
||||
public get(): R|kotlin/String|
|
||||
|
||||
public final val x: R|kotlin/Int|
|
||||
public get(): R|kotlin/Int| {
|
||||
^ this@R|/B|.F|/B.x|.<Unresolved name: length>#
|
||||
}
|
||||
|
||||
}
|
||||
Generated
+5
@@ -2062,6 +2062,11 @@ public class FirDiagnosticsTestGenerated extends AbstractFirDiagnosticsTest {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/properties/noBackingFieldForExtension.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("noBackingFieldInProperty.kt")
|
||||
public void testNoBackingFieldInProperty() throws Exception {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/properties/noBackingFieldInProperty.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("syntheticPropertiesForJavaAnnotations.kt")
|
||||
public void testSyntheticPropertiesForJavaAnnotations() throws Exception {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/properties/syntheticPropertiesForJavaAnnotations.kt");
|
||||
|
||||
+5
@@ -2062,6 +2062,11 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/properties/noBackingFieldForExtension.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("noBackingFieldInProperty.kt")
|
||||
public void testNoBackingFieldInProperty() throws Exception {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/properties/noBackingFieldInProperty.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("syntheticPropertiesForJavaAnnotations.kt")
|
||||
public void testSyntheticPropertiesForJavaAnnotations() throws Exception {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/properties/syntheticPropertiesForJavaAnnotations.kt");
|
||||
|
||||
+1
-1
@@ -143,7 +143,7 @@ open class FirDeclarationsResolveTransformer(transformer: FirBodyResolveTransfor
|
||||
storeVariableReturnType(property)
|
||||
}
|
||||
withLocalScopeCleanup {
|
||||
if (property.receiverTypeRef == null) {
|
||||
if (property.receiverTypeRef == null && property.returnTypeRef !is FirImplicitTypeRef) {
|
||||
addLocalScope(FirLocalScope().storeBackingField(property))
|
||||
}
|
||||
property.transformAccessors()
|
||||
|
||||
Vendored
+1
-1
@@ -5,7 +5,7 @@ val z get(): List<Int> {
|
||||
return bar()
|
||||
}
|
||||
|
||||
val u get(): String = field
|
||||
val u get(): String = <!UNRESOLVED_REFERENCE!>field<!>
|
||||
|
||||
fun <E> foo(): E = null!!
|
||||
fun <E> bar(): List<E> = null!!
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ class A {
|
||||
val z1 get() = <!INAPPLICABLE_CANDIDATE!>id<!>(z1)
|
||||
val z2 get() = <!INAPPLICABLE_CANDIDATE!>l<!>(z2)
|
||||
|
||||
val u get() = field
|
||||
val u get() = <!UNRESOLVED_REFERENCE!>field<!>
|
||||
}
|
||||
|
||||
fun <E> id(x: E) = x
|
||||
|
||||
+2
-2
@@ -21,7 +21,7 @@ val z2 get(): List<Int> {
|
||||
return bar()
|
||||
}
|
||||
|
||||
val u get(): String = field
|
||||
val u get(): String = <!UNRESOLVED_REFERENCE!>field<!>
|
||||
|
||||
// members.kt
|
||||
class A {
|
||||
@@ -68,4 +68,4 @@ object Outer {
|
||||
set(q) {
|
||||
x = q
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user