From 6dfc56a54544a129e91d11202d5f1c5424d57dab Mon Sep 17 00:00:00 2001 From: Alistair Thomas Date: Tue, 8 Nov 2016 00:36:58 +0000 Subject: [PATCH] vala: check a property has an accessor and/or a mutator Fixes https://bugzilla.gnome.org/show_bug.cgi?id=773956 --- tests/Makefile.am | 2 ++ tests/objects/bug773956-1.test | 10 ++++++++++ tests/objects/bug773956-2.test | 10 ++++++++++ vala/valaproperty.vala | 6 ++++++ 4 files changed, 28 insertions(+) create mode 100644 tests/objects/bug773956-1.test create mode 100644 tests/objects/bug773956-2.test diff --git a/tests/Makefile.am b/tests/Makefile.am index cfda178d9..d3c709a6b 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -190,6 +190,8 @@ TESTS = \ objects/bug760031.test \ objects/bug767092.test \ objects/bug768823.test \ + objects/bug773956-1.test \ + objects/bug773956-2.test \ objects/bug615830-1.test \ objects/bug615830-2.test \ errors/errors.vala \ diff --git a/tests/objects/bug773956-1.test b/tests/objects/bug773956-1.test new file mode 100644 index 000000000..94b161662 --- /dev/null +++ b/tests/objects/bug773956-1.test @@ -0,0 +1,10 @@ +Invalid Code + +class Foo : Object { + public int bar {} +} + +void main () { + new Foo (); +} + diff --git a/tests/objects/bug773956-2.test b/tests/objects/bug773956-2.test new file mode 100644 index 000000000..a0457afe7 --- /dev/null +++ b/tests/objects/bug773956-2.test @@ -0,0 +1,10 @@ +Invalid Code + +class Foo : Object { + private int bar {} +} + +void main () { + new Foo (); +} + diff --git a/vala/valaproperty.vala b/vala/valaproperty.vala index 9da3508ea..19aad24be 100644 --- a/vala/valaproperty.vala +++ b/vala/valaproperty.vala @@ -395,6 +395,12 @@ public class Vala.Property : Symbol, Lockable { property_type.check (context); + if (get_accessor == null && set_accessor == null) { + error = true; + Report.error (source_reference, "Property `%s' must have a `get' accessor and/or a `set' mutator".printf (get_full_name ())); + return false; + } + if (get_accessor != null) { get_accessor.check (context); } -- 2.47.2