[vala/staging: 4/4] vala: Report an error when initializing non-auto properties



commit 0d396f7daaf34596b159380b8ee2a57799ac9336
Author: Jeeyong Um <conr2d gmail com>
Date:   Wed Apr 18 21:59:49 2018 +0900

    vala: Report an error when initializing non-auto properties
    
    https://bugzilla.gnome.org/show_bug.cgi?id=795225

 tests/Makefile.am              |    3 +++
 tests/objects/bug795225-2.test |   14 ++++++++++++++
 tests/objects/bug795225-3.test |   13 +++++++++++++
 tests/objects/bug795225-4.test |   13 +++++++++++++
 vala/valaproperty.vala         |    6 ++++++
 5 files changed, 49 insertions(+), 0 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 5ec1473..64ce795 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -310,6 +310,9 @@ TESTS = \
        objects/bug783897.vala \
        objects/bug788964.vala \
        objects/bug795225-1.test \
+       objects/bug795225-2.test \
+       objects/bug795225-3.test \
+       objects/bug795225-4.test \
        errors/catch-error-code.vala \
        errors/errors.vala \
        errors/bug567181.vala \
diff --git a/tests/objects/bug795225-2.test b/tests/objects/bug795225-2.test
new file mode 100644
index 0000000..fc04d5a
--- /dev/null
+++ b/tests/objects/bug795225-2.test
@@ -0,0 +1,14 @@
+Invalid Code
+
+class Foo : Object {
+       int _fub = 0;
+
+       public int bar {
+               get { return _fub; }
+               set { _fub = value / 2; }
+               default = 42;
+       }
+}
+
+void main () {
+}
diff --git a/tests/objects/bug795225-3.test b/tests/objects/bug795225-3.test
new file mode 100644
index 0000000..1459a23
--- /dev/null
+++ b/tests/objects/bug795225-3.test
@@ -0,0 +1,13 @@
+Invalid Code
+
+class Foo : Object {
+       int _fub = 0;
+
+       public int bar {
+               get { return _fub; }
+               default = 42;
+       }
+}
+
+void main () {
+}
diff --git a/tests/objects/bug795225-4.test b/tests/objects/bug795225-4.test
new file mode 100644
index 0000000..1456299
--- /dev/null
+++ b/tests/objects/bug795225-4.test
@@ -0,0 +1,13 @@
+Invalid Code
+
+class Foo : Object {
+       int _fub = 0;
+
+       public int bar {
+               set { _fub = value / 2; }
+               default = 42;
+       }
+}
+
+void main () {
+}
diff --git a/vala/valaproperty.vala b/vala/valaproperty.vala
index ff95377..81bb849 100644
--- a/vala/valaproperty.vala
+++ b/vala/valaproperty.vala
@@ -480,6 +480,12 @@ public class Vala.Property : Symbol, Lockable {
                        set_accessor.check (context);
                }
 
+               if (initializer != null && field == null && !is_abstract) {
+                       error = true;
+                       Report.error (source_reference, "Property `%s' with custom `get' accessor and/or 
`set' mutator cannot have `default' value".printf (get_full_name ()));
+                       return false;
+               }
+
                if (initializer != null) {
                        initializer.check (context);
                }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]