]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
parser: Reduce the source reference of main block method to its beginning
authorRico Tzschichholz <ricotz@ubuntu.com>
Tue, 18 Jan 2022 13:33:15 +0000 (14:33 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Fri, 4 Feb 2022 18:58:32 +0000 (19:58 +0100)
The end contains broken information which lead to a crash while trying to
report this multi-line source reference.

tests/Makefile.am
tests/parser/main-block-minimal.c-expected [new file with mode: 0644]
tests/parser/main-block-minimal.vala [new file with mode: 0644]
vala/valaparser.vala

index a7bf1ee45f1861bb29378368c39c20a4ffd192c7..dcc42df06fc15449b8a2cd7e95304ecf9fb9e90c 100644 (file)
@@ -902,6 +902,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 (file)
index 0000000..a8b8a94
--- /dev/null
@@ -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 (file)
index 0000000..d029e43
--- /dev/null
@@ -0,0 +1 @@
+print ("foo");
index 581092de27873ac6e26de2825bbd04efc852f87d..5318bb26517a29e6055dfb83ca5c15abb0e3549a 100644 (file)
@@ -2517,7 +2517,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));