Delegated properties never require backing field #KT-10107 Fixed
This commit is contained in:
@@ -174,6 +174,8 @@ public interface BindingContext {
|
||||
backingFieldRequired; // this part is unused because we do not allow access to constructor parameters in member bodies
|
||||
}
|
||||
if (propertyDescriptor.getModality() == Modality.ABSTRACT) return false;
|
||||
if (declarationPsiElement instanceof KtProperty &&
|
||||
((KtProperty) declarationPsiElement).hasDelegate()) return false;
|
||||
PropertyGetterDescriptor getter = propertyDescriptor.getGetter();
|
||||
PropertySetterDescriptor setter = propertyDescriptor.getSetter();
|
||||
|
||||
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// See KT-10107: 'Variable must be initialized' for delegate with private set
|
||||
|
||||
class My {
|
||||
var delegate: String by kotlin.properties.Delegates.notNull()
|
||||
private set
|
||||
|
||||
// Error: Variable 'delegate' must be initialized
|
||||
val another: String = delegate
|
||||
|
||||
var delegateWithBackingField: String by kotlin.properties.Delegates.notNull()
|
||||
<!ACCESSOR_FOR_DELEGATED_PROPERTY!>private set(arg) { field = arg }<!>
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
package
|
||||
|
||||
public final class My {
|
||||
public constructor My()
|
||||
public final val another: kotlin.String
|
||||
public final var delegate: kotlin.String
|
||||
public final var delegateWithBackingField: kotlin.String
|
||||
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
|
||||
}
|
||||
@@ -95,6 +95,12 @@ public class DiagnosticsTestWithStdLibGenerated extends AbstractDiagnosticsTestW
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("PropertyDelegateWithPrivateSet.kt")
|
||||
public void testPropertyDelegateWithPrivateSet() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/PropertyDelegateWithPrivateSet.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("RedeclarationMainInMultiFileClass.kt")
|
||||
public void testRedeclarationMainInMultiFileClass() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/RedeclarationMainInMultiFileClass.kt");
|
||||
|
||||
Reference in New Issue
Block a user