From c24156ae84b0ceba59bb77a8c7b77c9fe2f5a1a9 Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Fri, 18 Sep 2015 16:13:05 +0300 Subject: [PATCH] "field": backing field usage deprecated warning, relevant diagnostics tests changed --- .../cfg/JetFlowInformationProvider.java | 3 ++ .../tests/AnonymousInitializers.kt | 2 +- .../diagnostics/tests/Constructors.kt | 2 +- compiler/testData/diagnostics/tests/Dollar.kt | 2 +- .../testData/diagnostics/tests/Properties.kt | 8 ++-- .../diagnostics/tests/UnusedVariables.kt | 2 +- .../backingField/ReadForwardInAnonymous.kt | 2 +- .../ReadForwardInPropertyInitializer.kt | 2 +- .../tests/backingField/ReadInAnonymous.kt | 2 +- .../ReadInAnotherPropertyIntializer.kt | 2 +- .../tests/backingField/ReadInFunction.kt | 2 +- .../backingField/kt462BackingFieldsResolve.kt | 22 +++++----- .../UninitializedOrReassignedVariables.kt | 40 +++++++++---------- .../checkBackingFieldException.kt | 2 +- .../diagnostics/tests/regressions/Jet17.kt | 2 +- .../diagnostics/tests/regressions/kt575.kt | 4 +- .../diagnostics/tests/scopes/kt421Scopes.kt | 2 +- .../testData/checker/AnonymousInitializers.kt | 2 +- idea/testData/checker/Constructors.kt | 2 +- idea/testData/checker/regression/Jet17.kt | 2 +- 20 files changed, 55 insertions(+), 52 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/cfg/JetFlowInformationProvider.java b/compiler/frontend/src/org/jetbrains/kotlin/cfg/JetFlowInformationProvider.java index 3973f48fc88..a9304f8aef0 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/cfg/JetFlowInformationProvider.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/cfg/JetFlowInformationProvider.java @@ -557,6 +557,9 @@ public class JetFlowInformationProvider { DeclarationDescriptor containingDeclaration = variableDescriptor.getContainingDeclaration(); if ((containingDeclaration instanceof ClassDescriptor) && DescriptorUtils.isAncestor(containingDeclaration, declarationDescriptor, false)) { + if (element instanceof JetSimpleNameExpression) { + report(Errors.BACKING_FIELD_USAGE_DEPRECATED.on((JetSimpleNameExpression) element), cxtx); + } return false; } report(Errors.INACCESSIBLE_BACKING_FIELD.on(element), cxtx); diff --git a/compiler/testData/diagnostics/tests/AnonymousInitializers.kt b/compiler/testData/diagnostics/tests/AnonymousInitializers.kt index c139a55789f..3d51c021e4d 100644 --- a/compiler/testData/diagnostics/tests/AnonymousInitializers.kt +++ b/compiler/testData/diagnostics/tests/AnonymousInitializers.kt @@ -13,7 +13,7 @@ interface NoC { class WithC() { val x : Int init { - $x = 1 + $x = 1 $y = 2 val b = x diff --git a/compiler/testData/diagnostics/tests/Constructors.kt b/compiler/testData/diagnostics/tests/Constructors.kt index fbcfcdaa2c6..b84839035da 100644 --- a/compiler/testData/diagnostics/tests/Constructors.kt +++ b/compiler/testData/diagnostics/tests/Constructors.kt @@ -24,7 +24,7 @@ class WithCPI_Dup(x : Int) { class WithCPI(x : Int) { val a = 1 - val b : Int = $a + val b : Int = $a val xy : Int = x } diff --git a/compiler/testData/diagnostics/tests/Dollar.kt b/compiler/testData/diagnostics/tests/Dollar.kt index 96173ecf238..bfba6fb50b9 100644 --- a/compiler/testData/diagnostics/tests/Dollar.kt +++ b/compiler/testData/diagnostics/tests/Dollar.kt @@ -7,7 +7,7 @@ open class `$`() { open class `$$`(`$$$$` : `$$$$$`?) : `$`() { val `$$$` : `$$$$$`? init { - $`$$$` = `$$$$` + $`$$$` = `$$$$` } open public fun `$$$$$$`() : `$$$$$`? { return `$$$` diff --git a/compiler/testData/diagnostics/tests/Properties.kt b/compiler/testData/diagnostics/tests/Properties.kt index df78cbced28..0b4e366194d 100644 --- a/compiler/testData/diagnostics/tests/Properties.kt +++ b/compiler/testData/diagnostics/tests/Properties.kt @@ -14,16 +14,16 @@ var x : Int = 1 + x class Test() { var a : Int = 111 - var b : Int get() = $a; set(x) {a = x; $a = x} + var b : Int get() = $a; set(x) {a = x; $a = x} init { - $b = $a - $a = $b + $b = $a + $a = $b a = $b } fun f() { - $b = $a + $b = $a a = $b } public val i = 1 diff --git a/compiler/testData/diagnostics/tests/UnusedVariables.kt b/compiler/testData/diagnostics/tests/UnusedVariables.kt index 1f13b8fafca..1d1822663a4 100644 --- a/compiler/testData/diagnostics/tests/UnusedVariables.kt +++ b/compiler/testData/diagnostics/tests/UnusedVariables.kt @@ -134,7 +134,7 @@ fun testBackingFieldsNotMarked() { val a = object { val x : Int init { - $x = 1 + $x = 1 } } } diff --git a/compiler/testData/diagnostics/tests/backingField/ReadForwardInAnonymous.kt b/compiler/testData/diagnostics/tests/backingField/ReadForwardInAnonymous.kt index 135edcfee1f..b1b1108d146 100644 --- a/compiler/testData/diagnostics/tests/backingField/ReadForwardInAnonymous.kt +++ b/compiler/testData/diagnostics/tests/backingField/ReadForwardInAnonymous.kt @@ -1,6 +1,6 @@ class ReadForward() { init { - val x = $a + val x = $a } val a = 1 diff --git a/compiler/testData/diagnostics/tests/backingField/ReadForwardInPropertyInitializer.kt b/compiler/testData/diagnostics/tests/backingField/ReadForwardInPropertyInitializer.kt index d5f35c0f7ca..0b0cb93c010 100644 --- a/compiler/testData/diagnostics/tests/backingField/ReadForwardInPropertyInitializer.kt +++ b/compiler/testData/diagnostics/tests/backingField/ReadForwardInPropertyInitializer.kt @@ -1,4 +1,4 @@ class ReadForward() { - val a = $b + val a = $b val b = 1 } diff --git a/compiler/testData/diagnostics/tests/backingField/ReadInAnonymous.kt b/compiler/testData/diagnostics/tests/backingField/ReadInAnonymous.kt index 751c6130e43..c70865f89ff 100644 --- a/compiler/testData/diagnostics/tests/backingField/ReadInAnonymous.kt +++ b/compiler/testData/diagnostics/tests/backingField/ReadInAnonymous.kt @@ -1,6 +1,6 @@ class ReadByAnotherPropertyInitializer() { val a = 1 init { - val x = $a + val x = $a } } diff --git a/compiler/testData/diagnostics/tests/backingField/ReadInAnotherPropertyIntializer.kt b/compiler/testData/diagnostics/tests/backingField/ReadInAnotherPropertyIntializer.kt index 864a13def97..c270af2d072 100644 --- a/compiler/testData/diagnostics/tests/backingField/ReadInAnotherPropertyIntializer.kt +++ b/compiler/testData/diagnostics/tests/backingField/ReadInAnotherPropertyIntializer.kt @@ -1,4 +1,4 @@ class ReadByAnotherPropertyInitializer() { val a = 1 - val b = $a + val b = $a } diff --git a/compiler/testData/diagnostics/tests/backingField/ReadInFunction.kt b/compiler/testData/diagnostics/tests/backingField/ReadInFunction.kt index 9ed84b87bcc..6d1443d81fc 100644 --- a/compiler/testData/diagnostics/tests/backingField/ReadInFunction.kt +++ b/compiler/testData/diagnostics/tests/backingField/ReadInFunction.kt @@ -1,4 +1,4 @@ class ReadByAnotherPropertyInitializer() { val a = 1 - fun ff() = $a + fun ff() = $a } diff --git a/compiler/testData/diagnostics/tests/backingField/kt462BackingFieldsResolve.kt b/compiler/testData/diagnostics/tests/backingField/kt462BackingFieldsResolve.kt index 6e1d68168d2..1a8f409ea5d 100644 --- a/compiler/testData/diagnostics/tests/backingField/kt462BackingFieldsResolve.kt +++ b/compiler/testData/diagnostics/tests/backingField/kt462BackingFieldsResolve.kt @@ -49,7 +49,7 @@ abstract class TestInitializationWithoutBackingField() { abstract class TestInitializationThroughBackingField() { val valWithBackingField : Int init { - $valWithBackingField = 2 + $valWithBackingField = 2 } val valWithoutBackingField : Int @@ -60,12 +60,12 @@ abstract class TestInitializationThroughBackingField() { var finalDefaultVar : Int init { - $finalDefaultVar = 3 + $finalDefaultVar = 3 } open var openVar : Int init { - $openVar = 4 + $openVar = 4 } var varWithCustomSetter : Int @@ -73,7 +73,7 @@ abstract class TestInitializationThroughBackingField() { field = v } init { - $varWithCustomSetter = 3 + $varWithCustomSetter = 3 } var varWithoutBackingField : Int @@ -92,12 +92,12 @@ abstract class TestInitializationThroughBackingField() { class TestBackingFieldsVisibility() { var a : Int = 712 init { - $a = 37 + $a = 37 this.$a = 357 } fun foo() { - $a = 334 + $a = 334 this.$a = 347 } @@ -110,7 +110,7 @@ class TestBackingFieldsVisibility() { val x = $topLevelVar inner class Inner() { - val z = this@TestBackingFieldsVisibility.$x + val z = this@TestBackingFieldsVisibility.$x } abstract val w = 11 @@ -150,7 +150,7 @@ class T() { return 1 } - var r: Int = $x + var r: Int = $x set(v: Int) { if (true) { field = 33 @@ -161,11 +161,11 @@ class T() { } fun bar() { - $x = 34 + $x = 34 val o = object { - val y = $x + val y = $x init { - $x = 422 + $x = 422 } } } diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/UninitializedOrReassignedVariables.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/UninitializedOrReassignedVariables.kt index e87866dffdb..8a236f5b7d0 100644 --- a/compiler/testData/diagnostics/tests/controlFlowAnalysis/UninitializedOrReassignedVariables.kt +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/UninitializedOrReassignedVariables.kt @@ -113,16 +113,16 @@ val z = 10 class AnonymousInitializers(var a: String, val b: String) { init { - $a = "30" + $a = "30" a = "s" - $b = "3" + $b = "3" b = "tt" //repeat for b } val i: Int init { - $i = 121 + $i = 121 } init { @@ -134,7 +134,7 @@ class AnonymousInitializers(var a: String, val b: String) { get() = 20 init { - $i = 13 + $i = 13 $j = 30 j = 34 } @@ -145,31 +145,31 @@ class AnonymousInitializers(var a: String, val b: String) { k = "a" } else { - $k = "b" + $k = "b" } } val l: String init { if (1 < 3) { - $l = "a" + $l = "a" } else { - $l = "b" + $l = "b" } } val o: String init { if (1 < 3) { - $o = "a" + $o = "a" } } var m: Int = 30 init { - $m = 400 + $m = 400 } val n: Int @@ -177,7 +177,7 @@ class AnonymousInitializers(var a: String, val b: String) { init { while (n == 0) { } - $n = 10 + $n = 10 while (n == 0) { } } @@ -198,7 +198,7 @@ class LocalValsVsProperties(val a: Int, w: Int) : Open(a, w) { val x : Int val y : Int init { - $x = 1 + $x = 1 val b = x } val b = a @@ -214,7 +214,7 @@ class LocalValsVsProperties(val a: Int, w: Int) : Open(a, w) { var yy : Int init { w += 1 - $yy = w + $yy = w } } @@ -223,8 +223,8 @@ class Outer() { var b : Int init { - $a = 1 - $b = 1 + $a = 1 + $b = 1 } inner class Inner() { @@ -242,7 +242,7 @@ class Outer() { class ForwardAccessToBackingField() { //kt-147 val a = $a // error - val b = $c // error + val b = $c // error val c = 1 } @@ -251,7 +251,7 @@ class ClassObject() { val x : Int init { - $x = 1 + $x = 1 } @@ -268,8 +268,8 @@ fun foo() { val y : Int val z : Int init { - $x = 1 - $z = 3 + $x = 1 + $z = 3 } fun foo() { y = 10 @@ -288,7 +288,7 @@ class TestObjectExpression() { if (true) x = 12 else - $x = 1 + $x = 1 } fun inner1() { y = 101 @@ -308,7 +308,7 @@ object TestObjectDeclaration { val x : Int val y : Int init { - $x = 1 + $x = 1 } fun foo() { diff --git a/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/checkBackingFieldException.kt b/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/checkBackingFieldException.kt index edeb9fcc3d4..7c090d157fd 100644 --- a/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/checkBackingFieldException.kt +++ b/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/checkBackingFieldException.kt @@ -3,7 +3,7 @@ package h class Square() { var size : Double = set(value) { - $area = size * size + $area = size * size } var area : Double diff --git a/compiler/testData/diagnostics/tests/regressions/Jet17.kt b/compiler/testData/diagnostics/tests/regressions/Jet17.kt index 0b2eedc527d..7b710eaca10 100644 --- a/compiler/testData/diagnostics/tests/regressions/Jet17.kt +++ b/compiler/testData/diagnostics/tests/regressions/Jet17.kt @@ -2,5 +2,5 @@ class WithC() { val a = 1 - val b = $a // error here, but must not be + val b = $a // error here, but must not be } diff --git a/compiler/testData/diagnostics/tests/regressions/kt575.kt b/compiler/testData/diagnostics/tests/regressions/kt575.kt index 5d131517cfe..67c36dd42cc 100644 --- a/compiler/testData/diagnostics/tests/regressions/kt575.kt +++ b/compiler/testData/diagnostics/tests/regressions/kt575.kt @@ -12,7 +12,7 @@ class Creature() { var bbb : Int init { - $bbb = 1 + $bbb = 1 } } @@ -20,7 +20,7 @@ class Creature() { var ccc : Int init { - $ccc = 2 + $ccc = 2 } } diff --git a/compiler/testData/diagnostics/tests/scopes/kt421Scopes.kt b/compiler/testData/diagnostics/tests/scopes/kt421Scopes.kt index 1e7138507ad..3678c3f7272 100644 --- a/compiler/testData/diagnostics/tests/scopes/kt421Scopes.kt +++ b/compiler/testData/diagnostics/tests/scopes/kt421Scopes.kt @@ -4,5 +4,5 @@ class A() { val c = 1 val a = b - val b = $c // '$c' is unresolved + val b = $c // '$c' is unresolved } diff --git a/idea/testData/checker/AnonymousInitializers.kt b/idea/testData/checker/AnonymousInitializers.kt index 14b4d8fe654..0e69a15ce42 100644 --- a/idea/testData/checker/AnonymousInitializers.kt +++ b/idea/testData/checker/AnonymousInitializers.kt @@ -13,7 +13,7 @@ interface NoC { class WithC() { val x : Int init { - $x = 1 + $x = 1 $y = 2 val b = x diff --git a/idea/testData/checker/Constructors.kt b/idea/testData/checker/Constructors.kt index a242960bc7a..727c3a26b0e 100644 --- a/idea/testData/checker/Constructors.kt +++ b/idea/testData/checker/Constructors.kt @@ -28,7 +28,7 @@ class WithCPI_Dup(x : Int) { class WithCPI(x : Int) { val a = 1 - val b : Int = $a + val b : Int = $a val xy : Int = x } diff --git a/idea/testData/checker/regression/Jet17.kt b/idea/testData/checker/regression/Jet17.kt index 32cf98cd2fc..e6cf06c54dc 100644 --- a/idea/testData/checker/regression/Jet17.kt +++ b/idea/testData/checker/regression/Jet17.kt @@ -2,5 +2,5 @@ class WithC() { val a = 1 - val b = $a // error here, but must not be + val b = $a // error here, but must not be } \ No newline at end of file