diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/BindingContext.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/BindingContext.java index 43bb93638d4..fded8ff905c 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/BindingContext.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/BindingContext.java @@ -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(); diff --git a/compiler/testData/diagnostics/testsWithStdLib/PropertyDelegateWithPrivateSet.kt b/compiler/testData/diagnostics/testsWithStdLib/PropertyDelegateWithPrivateSet.kt new file mode 100644 index 00000000000..864d8c11997 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/PropertyDelegateWithPrivateSet.kt @@ -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() + private set(arg) { field = arg } +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/PropertyDelegateWithPrivateSet.txt b/compiler/testData/diagnostics/testsWithStdLib/PropertyDelegateWithPrivateSet.txt new file mode 100644 index 00000000000..cdd9ab12c45 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/PropertyDelegateWithPrivateSet.txt @@ -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 +} diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java index 9dd26e4d8b6..ef57788e999 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java @@ -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");