[vala/staging] parser: Reduce the source reference of main block method to its beginning



commit 8c72e14117f474bb657ecb3bde2efc352e9a164c
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Tue Jan 18 14:33:15 2022 +0100

    parser: Reduce the source reference of main block method to its beginning
    
    The end contains broken information which lead to a crash while trying to
    report this multi-line source reference.

 tests/Makefile.am                          |  1 +
 tests/parser/main-block-minimal.c-expected | 21 +++++++++++++++++++++
 tests/parser/main-block-minimal.vala       |  1 +
 vala/valaparser.vala                       |  2 +-
 4 files changed, 24 insertions(+), 1 deletion(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index f95b6bfaa..31a67f6e7 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -918,6 +918,7 @@ TESTS = \
        parser/local-variable-array-type-invalid.test \
        parser/lock-statement.vala \
        parser/main-block.vala \
+       parser/main-block-minimal.vala \
        parser/member-access-pointer.vala \
        parser/member-initializer.vala \
        parser/member-initializer-empty.vala \
diff --git a/tests/parser/main-block-minimal.c-expected b/tests/parser/main-block-minimal.c-expected
new file mode 100644
index 000000000..a8b8a94dc
--- /dev/null
+++ b/tests/parser/main-block-minimal.c-expected
@@ -0,0 +1,21 @@
+/* parser_main_block_minimal.c generated by valac, the Vala compiler
+ * generated from parser_main_block_minimal.vala, do not modify */
+
+#include <glib.h>
+
+static void _vala_main (void);
+
+static void
+_vala_main (void)
+{
+       g_print ("foo");
+}
+
+int
+main (int argc,
+      char ** argv)
+{
+       _vala_main ();
+       return 0;
+}
+
diff --git a/tests/parser/main-block-minimal.vala b/tests/parser/main-block-minimal.vala
new file mode 100644
index 000000000..d029e43fa
--- /dev/null
+++ b/tests/parser/main-block-minimal.vala
@@ -0,0 +1 @@
+print ("foo");
diff --git a/vala/valaparser.vala b/vala/valaparser.vala
index 87817fd6b..2f3a99016 100644
--- a/vala/valaparser.vala
+++ b/vala/valaparser.vala
@@ -2637,7 +2637,7 @@ public class Vala.Parser : CodeVisitor {
        void parse_main_block (Symbol parent) throws ParseError {
                var begin = get_location ();
 
-               var method = new Method ("main", new VoidType (), get_src (begin));
+               var method = new Method ("main", new VoidType (), new SourceReference (scanner.source_file, 
begin, begin));
                method.access = SymbolAccessibility.PUBLIC;
                method.binding = MemberBinding.STATIC;
                method.body = new Block (get_src (begin));


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]