[vala/0.40: 4/4] parser: `owned` is not allowed on Constants
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/0.40: 4/4] parser: `owned` is not allowed on Constants
- Date: Mon, 14 Oct 2019 12:31:05 +0000 (UTC)
commit 8401df94df05cbce0690f50f9a37c2a0a18a9af6
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Fri Oct 11 16:48:29 2019 +0200
parser: `owned` is not allowed on Constants
This avoids criticals and broken c-code.
tests/Makefile.am | 2 ++
tests/parser/constant-local-owned.test | 5 +++++
tests/parser/constant-owned.test | 6 ++++++
vala/valaparser.vala | 8 ++++++++
4 files changed, 21 insertions(+)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 7f1cc7e97..1334429c4 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -476,6 +476,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 6abe6eb82..dcea02bdf 100644
--- a/vala/valaparser.vala
+++ b/vala/valaparser.vala
@@ -1895,6 +1895,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);
}
@@ -2635,6 +2639,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 ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]