diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java index b5158340ebc..994d932e34c 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java @@ -280,9 +280,9 @@ public class DefaultErrorMessages { MAP.put(VAL_OR_VAR_ON_SECONDARY_CONSTRUCTOR_PARAMETER, "''{0}'' on secondary constructor parameter is not allowed", TO_STRING); MAP.put(INITIALIZATION_USING_BACKING_FIELD_CUSTOM_SETTER, - "This property has a custom setter, so initialization using backing field required", NAME); + "This property cannot be initialized inside ''init'' block because it has a custom setter", NAME); MAP.put(INITIALIZATION_USING_BACKING_FIELD_OPEN_SETTER, - "Setter of this property can be overridden, so initialization using backing field required", NAME); + "This property cannot be initialized inside ''init'' block because it has an open setter", NAME); MAP.put(UNREACHABLE_CODE, "Unreachable code", TO_STRING); diff --git a/compiler/testData/codegen/box/objects/kt535.kt b/compiler/testData/codegen/box/objects/kt535.kt new file mode 100644 index 00000000000..693d73f7682 --- /dev/null +++ b/compiler/testData/codegen/box/objects/kt535.kt @@ -0,0 +1,21 @@ +class Identifier(t : T?, myHasDollar : Boolean) { + private val myT : T? + + public fun getName() : T? { return myT } + + companion object { + open public fun init(name : T?) : Identifier { + val __ = Identifier(name, false) + return __ + } + } + init { + myT = t + } +} + +fun box() : String { + var i3 : Identifier? = Identifier.init("name") + System.out?.println(i3?.getName()) + return "OK" +} diff --git a/compiler/testData/diagnostics/tests/backingField/CustomGetSet.kt b/compiler/testData/diagnostics/tests/backingField/CustomGetSet.kt new file mode 100644 index 00000000000..2320f9f786c --- /dev/null +++ b/compiler/testData/diagnostics/tests/backingField/CustomGetSet.kt @@ -0,0 +1,11 @@ +class Flower() { + + var minusOne: Int = 1 + get() = field + 1 + set(n: Int) { field = n - 1 } + + var oldSyntax: Int = 1 + get() = $oldSyntax - 1 + set(arg) { $oldSyntax = arg + 1 } + +} diff --git a/compiler/testData/diagnostics/tests/backingField/CustomGetSet.txt b/compiler/testData/diagnostics/tests/backingField/CustomGetSet.txt new file mode 100644 index 00000000000..86a6c64010d --- /dev/null +++ b/compiler/testData/diagnostics/tests/backingField/CustomGetSet.txt @@ -0,0 +1,10 @@ +package + +public final class Flower { + public constructor Flower() + public final var minusOne: kotlin.Int + public final var oldSyntax: kotlin.Int + 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/JetDiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java index 61015c45b2e..b0e04f61566 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java @@ -1362,6 +1362,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest { JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/tests/backingField"), Pattern.compile("^(.+)\\.kt$"), true); } + @TestMetadata("CustomGetSet.kt") + public void testCustomGetSet() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/backingField/CustomGetSet.kt"); + doTest(fileName); + } + @TestMetadata("CustomGetVal.kt") public void testCustomGetVal() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/backingField/CustomGetVal.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxCodegenTestGenerated.java index b599269f6fe..6c41e3dddce 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxCodegenTestGenerated.java @@ -5650,6 +5650,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { doTest(fileName); } + @TestMetadata("kt535.kt") + public void testKt535() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/objects/kt535.kt"); + doTest(fileName); + } + @TestMetadata("kt560.kt") public void testKt560() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/objects/kt560.kt"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/PropertyAccessTest.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/PropertyAccessTest.java index ec34c4b5602..cb8806867fd 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/PropertyAccessTest.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/PropertyAccessTest.java @@ -38,10 +38,6 @@ public final class PropertyAccessTest extends SingleFileTranslationTest { fooBoxTest(); } - public void testBackendField() throws Exception { - checkFooBoxIsOk(); - } - public void testSetter() throws Exception { checkFooBoxIsOk(); } diff --git a/js/js.translator/testData/propertyAccess/cases/backendField.kt b/js/js.translator/testData/propertyAccess/cases/backendField.kt deleted file mode 100644 index 8a7aaa98bd5..00000000000 --- a/js/js.translator/testData/propertyAccess/cases/backendField.kt +++ /dev/null @@ -1,17 +0,0 @@ -package foo - -class A { - val a: Int = 1 - get() = field + 1 - - fun getA(): Int { - return a - } -} - -fun box(): String { - val a = A() - if (a.a != 2) return "A().a != 2, it: ${a.a}" - if (a.getA() != 2) return "A().getA() != 2, it: ${a.getA()}" - return "OK" -} \ No newline at end of file