From: Jeeyong Um Date: Wed, 18 Apr 2018 12:59:49 +0000 (+0900) Subject: vala: Report an error when initializing non-auto properties X-Git-Tag: 0.41.90~172 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=refs%2Fkeep-around%2F0d396f7daaf34596b159380b8ee2a57799ac9336;p=thirdparty%2Fvala.git vala: Report an error when initializing non-auto properties https://bugzilla.gnome.org/show_bug.cgi?id=795225 --- 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); }