]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
parser: Clean up creation of constant declaration
authorRico Tzschichholz <ricotz@ubuntu.com>
Sun, 6 Feb 2022 13:29:55 +0000 (14:29 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Wed, 9 Feb 2022 12:56:20 +0000 (13:56 +0100)
vala/valaparser.vala

index 4d860f859add5f33877a8d653383b22261b74529..34418afe710eb24968c6111a62fdc28a0b5475ad 100644 (file)
@@ -2913,6 +2913,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;
@@ -2920,7 +2921,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;
@@ -2938,11 +2945,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);
        }