From 0d396f7daaf34596b159380b8ee2a57799ac9336 Mon Sep 17 00:00:00 2001 From: Jeeyong Um Date: Wed, 18 Apr 2018 21:59:49 +0900 Subject: [PATCH] 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(+) create mode 100644 tests/objects/bug795225-2.test create mode 100644 tests/objects/bug795225-3.test create mode 100644 tests/objects/bug795225-4.test diff --git a/tests/Makefile.am b/tests/Makefile.am index 5ec1473c5..64ce795f3 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 000000000..fc04d5aa7 --- /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 000000000..1459a23c7 --- /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 000000000..1456299ef --- /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 ff953777c..81bb84950 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); } -- 2.47.2