]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
parser: Improve source-location for local Constant declarations
authorRico Tzschichholz <ricotz@ubuntu.com>
Wed, 10 Apr 2019 12:12:21 +0000 (14:12 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Tue, 6 Aug 2019 11:23:19 +0000 (13:23 +0200)
vala/valaparser.vala

index aa290e084b22585cc7662989e0d1d824bb72962b..d03fa2fcc10f26a40aeb6398f85d15003891ee7d 100644 (file)
@@ -1832,6 +1832,7 @@ public class Vala.Parser : CodeVisitor {
        }
 
        void parse_local_constant_declarations (Block block) throws ParseError {
+               var begin = get_location ();
                expect (TokenType.CONST);
                var constant_type = parse_type (false, false);
 
@@ -1841,10 +1842,17 @@ public class Vala.Parser : CodeVisitor {
                        array_type.element_type.value_owned = false;
                }
 
+               bool is_first = true;
                do {
+                       if (!is_first) {
+                               begin = get_location ();
+                       } else {
+                               is_first = false;
+                       }
+
                        DataType type_copy = constant_type.copy ();
                        var local = parse_local_constant (type_copy);
-                       block.add_statement (new DeclarationStatement (local, local.source_reference));
+                       block.add_statement (new DeclarationStatement (local, get_src (begin)));
                        block.add_local_constant (local);
                        local.active = false;
                } while (accept (TokenType.COMMA));
@@ -1854,13 +1862,13 @@ public class Vala.Parser : CodeVisitor {
        Constant parse_local_constant (DataType constant_type) throws ParseError {
                var begin = get_location ();
                string id = parse_identifier ();
-
                var type = parse_inline_array_type (constant_type);
+               var src = get_src (begin);
 
                expect (TokenType.ASSIGN);
                var initializer = parse_expression ();
 
-               return new Constant (id, type, initializer, get_src (begin));
+               return new Constant (id, type, initializer, src);
        }
 
        Statement parse_expression_statement () throws ParseError {