]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
vala: Report an error when initializing non-auto properties 0d396f7daaf34596b159380b8ee2a57799ac9336
authorJeeyong Um <conr2d@gmail.com>
Wed, 18 Apr 2018 12:59:49 +0000 (21:59 +0900)
committerRico Tzschichholz <ricotz@ubuntu.com>
Thu, 19 Apr 2018 15:41:10 +0000 (17:41 +0200)
https://bugzilla.gnome.org/show_bug.cgi?id=795225

tests/Makefile.am
tests/objects/bug795225-2.test [new file with mode: 0644]
tests/objects/bug795225-3.test [new file with mode: 0644]
tests/objects/bug795225-4.test [new file with mode: 0644]
vala/valaproperty.vala

index 5ec1473c5af0368120c2f62499486c66394fc4cf..64ce795f35a73d073c8b82930a103022fc40ceda 100644 (file)
@@ -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 (file)
index 0000000..fc04d5a
--- /dev/null
@@ -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 (file)
index 0000000..1459a23
--- /dev/null
@@ -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 (file)
index 0000000..1456299
--- /dev/null
@@ -0,0 +1,13 @@
+Invalid Code
+
+class Foo : Object {
+       int _fub = 0;
+
+       public int bar {
+               set { _fub = value / 2; }
+               default = 42;
+       }
+}
+
+void main () {
+}
index ff953777cbebcf3536f30f278cfabd9b30b2fa4a..81bb84950788ce02e36cd1365c61afd3060cce59 100644 (file)
@@ -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);
                }