From: Rico Tzschichholz Date: Sun, 6 Feb 2022 13:29:55 +0000 (+0100) Subject: parser: Clean up creation of constant declaration X-Git-Tag: 0.55.3~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fab202fdec0abbf166743c0c316e5d61d049c46a;p=thirdparty%2Fvala.git parser: Clean up creation of constant declaration --- 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); }