From: Rico Tzschichholz Date: Fri, 11 Oct 2019 14:48:29 +0000 (+0200) Subject: parser: `owned` is not allowed on Constants X-Git-Tag: 0.44.10~39 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a638c063f93bb7034aa21061b164d024d92b3007;p=thirdparty%2Fvala.git parser: `owned` is not allowed on Constants This avoids criticals and broken c-code. --- diff --git a/tests/Makefile.am b/tests/Makefile.am index 959af3728..180c22e97 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -526,6 +526,8 @@ TESTS = \ parser/assignment.vala \ parser/attribute-duplicate.test \ parser/attribute-wrong-number.test \ + parser/constant-owned.test \ + parser/constant-local-owned.test \ parser/constructor-class-exists.test \ parser/constructor-exists.test \ parser/constructor-no-new.test \ diff --git a/tests/parser/constant-local-owned.test b/tests/parser/constant-local-owned.test new file mode 100644 index 000000000..c8d696454 --- /dev/null +++ b/tests/parser/constant-local-owned.test @@ -0,0 +1,5 @@ +Invalid Code + +void main () { + const owned string FOO = "foo"; +} diff --git a/tests/parser/constant-owned.test b/tests/parser/constant-owned.test new file mode 100644 index 000000000..41e7ed200 --- /dev/null +++ b/tests/parser/constant-owned.test @@ -0,0 +1,6 @@ +Invalid Code + +const owned string FOO = "foo"; + +void main () { +} diff --git a/vala/valaparser.vala b/vala/valaparser.vala index c2fe002d3..0e14307ff 100644 --- a/vala/valaparser.vala +++ b/vala/valaparser.vala @@ -1883,6 +1883,10 @@ public class Vala.Parser : CodeVisitor { expect (TokenType.ASSIGN); var initializer = parse_expression (); + if (type.value_owned) { + Report.error (src, "`owned' is not allowed on constants"); + } + return new Constant (id, type, initializer, src); } @@ -2642,6 +2646,10 @@ public class Vala.Parser : CodeVisitor { Report.warning (c.source_reference, "the modifier `static' is not applicable to constants"); } + if (type.value_owned) { + Report.error (c.source_reference, "`owned' is not allowed on constants"); + } + if (accept (TokenType.ASSIGN)) { c.value = parse_expression (); }