summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRico Tzschichholz <ricotz@ubuntu.com>2022-02-06 14:29:55 +0100
committerRico Tzschichholz <ricotz@ubuntu.com>2022-02-06 14:29:55 +0100
commitfab202fdec0abbf166743c0c316e5d61d049c46a (patch)
tree6b011834069be5ee5fb7a3a8393ba08de50c52c0
parent7b3fc94ce5d057bd7d26ce0e2d891a58710f6903 (diff)
downloadvala-fab202fdec0abbf166743c0c316e5d61d049c46a.tar.gz
parser: Clean up creation of constant declaration
-rw-r--r--vala/valaparser.vala14
1 files changed, 8 insertions, 6 deletions
diff --git a/vala/valaparser.vala b/vala/valaparser.vala
index a8f083a82..d81fc3544 100644
--- a/vala/valaparser.vala
+++ b/vala/valaparser.vala
@@ -3116,6 +3116,7 @@ public class Vala.Parser : CodeVisitor {
string id = parse_identifier ();
type = parse_inline_array_type (type);
+ var src = get_src (begin);
// constant arrays don't own their element
unowned ArrayType? array_type = type as ArrayType;
@@ -3123,7 +3124,13 @@ public class Vala.Parser : CodeVisitor {
array_type.element_type.value_owned = false;
}
- var c = new Constant (id, type, null, get_src (begin), comment);
+ Expression? initializer = null;
+ if (accept (TokenType.ASSIGN)) {
+ initializer = parse_expression ();
+ }
+ expect (TokenType.SEMICOLON);
+
+ var c = new Constant (id, type, initializer, src, comment);
c.access = access;
if (ModifierFlags.EXTERN in flags) {
c.is_extern = true;
@@ -3141,11 +3148,6 @@ public class Vala.Parser : CodeVisitor {
Report.error (c.source_reference, "`owned' is not allowed on constants");
}
- if (accept (TokenType.ASSIGN)) {
- c.value = parse_expression ();
- }
- expect (TokenType.SEMICOLON);
-
parent.add_constant (c);
}