Commit ed1e5cb3f6

Andrew Kelley <andrew@ziglang.org>
2021-02-20 05:47:11
stage2: fix a couple off by one errors
All stage2 tests are passing again in this branch. Remaining checklist for this branch: * get the rest of the zig fmt test cases passing - re-enable the translate-c test case that is blocking on this * implement the 2 `@panic(TODO)`'s in parse.zig * use fn_proto not fn_decl for extern function declarations
1 parent 5b597a1
Changed files (3)
lib
std
src
test
stage2
lib/std/zig/ast.zig
@@ -2566,8 +2566,10 @@ pub const Node = struct {
         /// before the final rbrace.
         struct_init_comma,
         /// `lhs(rhs)`. rhs can be omitted.
+        /// main_token is the lparen.
         call_one,
         /// `lhs(rhs,)`. rhs can be omitted.
+        /// main_token is the lparen.
         call_one_comma,
         /// `async lhs(rhs)`. rhs can be omitted.
         async_call_one,
src/astgen.zig
@@ -901,7 +901,7 @@ fn labeledBlockExpr(
     const token_tags = tree.tokens.items(.tag);
 
     const lbrace = main_tokens[block_node];
-    const label_token = lbrace - 1;
+    const label_token = lbrace - 2;
     assert(token_tags[label_token] == .identifier);
     const src = token_starts[lbrace];
 
@@ -3072,7 +3072,7 @@ fn multilineStringLiteral(
     // Count the number of bytes to allocate.
     const len: usize = len: {
         var tok_i = start;
-        var len: usize = 0;
+        var len: usize = end - start + 1;
         while (tok_i <= end) : (tok_i += 1) {
             // 2 for the '//' + 1 for '\n'
             len += tree.tokenSlice(tok_i).len - 3;
test/stage2/test.zig
@@ -1088,7 +1088,7 @@ pub fn addCases(ctx: *TestContext) !void {
             \\    _ = foo;
             \\}
             \\extern var foo;
-        , &[_][]const u8{":4:1: error: unable to infer variable type"});
+        , &[_][]const u8{":4:8: error: unable to infer variable type"});
     }
 
     {
@@ -1194,12 +1194,12 @@ pub fn addCases(ctx: *TestContext) !void {
             \\comptime {
             \\    foo: while (true) {}
             \\}
-        , &[_][]const u8{":2:5: error: unused while label"});
+        , &[_][]const u8{":2:5: error: unused while loop label"});
         case.addError(
             \\comptime {
             \\    foo: for ("foo") |_| {}
             \\}
-        , &[_][]const u8{":2:5: error: unused for label"});
+        , &[_][]const u8{":2:5: error: unused for loop label"});
         case.addError(
             \\comptime {
             \\    blk: {blk: {}}
@@ -1294,6 +1294,10 @@ pub fn addCases(ctx: *TestContext) !void {
         ,
             "",
         );
+        // TODO this should be :8:21 not :8:19. we need to improve source locations
+        // to be relative to the containing Decl so that they can survive when the byte
+        // offset of a previous Decl changes. Here the change from 7 to 999 introduces
+        // +2 to the byte offset and makes the error location wrong by 2 bytes.
         case.addError(
             \\export fn _start() noreturn {
             \\    const y = fibonacci(999);
@@ -1314,7 +1318,7 @@ pub fn addCases(ctx: *TestContext) !void {
             \\    );
             \\    unreachable;
             \\}
-        , &[_][]const u8{":8:10: error: evaluation exceeded 1000 backwards branches"});
+        , &[_][]const u8{":8:19: error: evaluation exceeded 1000 backwards branches"});
     }
     {
         var case = ctx.exe("orelse at comptime", linux_x64);