]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
parser: `owned` is not allowed on Constants
authorRico Tzschichholz <ricotz@ubuntu.com>
Fri, 11 Oct 2019 14:48:29 +0000 (16:48 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Mon, 14 Oct 2019 07:43:30 +0000 (09:43 +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 959af3728c1ceab50d1d446656b1a0b6e75db342..180c22e974a8e0df1a48a19efed1612b517e7d22 100644 (file)
@@ -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 (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 c2fe002d36076bf15717439e7e2707a8982b6219..0e14307ffc4ee4f52bba0c19a27f417f8453c887 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 ();
                }