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



commit 55afa78da8cb6da94e9d0e92f396a3d7169a8f95
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         |    5 +++++
 5 files changed, 48 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 2a83295..8ca1342 100644
--- a/vala/valaproperty.vala
+++ b/vala/valaproperty.vala
@@ -453,6 +453,11 @@ 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 ()));
+               }
+
                if (initializer != null) {
                        initializer.check (context);
                }


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