]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
parser: `owned` is not allowed on Constants 9776597f710c407990523e0d9823e399c0d79f1a
authorRico Tzschichholz <ricotz@ubuntu.com>
Fri, 11 Oct 2019 14:48:29 +0000 (16:48 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Fri, 11 Oct 2019 14:58:27 +0000 (16:58 +0200)
This avoids criticals and broken c-code.

tests/Makefile.am
tests/parser/constant-local-owned.test [new file with mode: 0644]
tests/parser/constant-owned.test [new file with mode: 0644]
vala/valaparser.vala

index ba8f2b0c65750eacd4f0b8f1dc91fe07131ac0d1..5b56bb89d05bf546b7a9df64e041f159750a0cf3 100644 (file)
@@ -538,6 +538,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 (file)
index 0000000..c8d6964
--- /dev/null
@@ -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 (file)
index 0000000..41e7ed2
--- /dev/null
@@ -0,0 +1,6 @@
+Invalid Code
+
+const owned string FOO = "foo";
+
+void main () {
+}
index 0a424333a1dedf8b11eadc8042b08202fd38123b..fe4e1691573a4b86f973bfa73b8d47c2272d7dae 100644 (file)
@@ -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 ();
                }