aboutsummaryrefslogtreecommitdiff
path: root/src/Compilation.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-03-19 23:06:19 -0700
committerAndrew Kelley <andrew@ziglang.org>2021-03-19 23:15:18 -0700
commit56677f2f2da41af5999b84b7f740d7bc463d1032 (patch)
treeacc501152db65974b9e381d72de6c6dc385ad667 /src/Compilation.zig
parent937c43ddf1297f355cc535adf3ec08f9f741b6c8 (diff)
downloadzig-56677f2f2da41af5999b84b7f740d7bc463d1032.tar.gz
zig-56677f2f2da41af5999b84b7f740d7bc463d1032.zip
astgen: support blocks
We are now passing this test: ```zig export fn _start() noreturn {} ``` ``` test.zig:1:30: error: expected noreturn, found void ``` I ran into an issue where we get an integer overflow trying to compute node index offsets from the containing Decl. The problem is that the parser adds the Decl node after adding the child nodes. For some things, it is easy to reserve the node index and then set it later, however, for this case, it is not a trivial code change, because depending on tokens after parsing the decl determines whether we want to add a new node or not. Possible strategies here: 1. Rework the parser code to make sure that Decl nodes are before children nodes in the AST node array. 2. Use signed integers for Decl node offsets. 3. Just flip the order of subtraction and addition. Expect Decl Node index to be greater than children Node indexes. I opted for (3) because it seems like the simplest thing to do. We'll want to unify the logic for computing the offsets though because if the logic gets repeated, it will probably get repeated wrong.
Diffstat (limited to 'src/Compilation.zig')
-rw-r--r--src/Compilation.zig4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/Compilation.zig b/src/Compilation.zig
index 41acd04ef4..30fcdefc99 100644
--- a/src/Compilation.zig
+++ b/src/Compilation.zig
@@ -317,7 +317,7 @@ pub const AllErrors = struct {
for (notes) |*note, i| {
const module_note = module_err_msg.notes[i];
const source = try module_note.src_loc.fileScope().getSource(module);
- const byte_offset = try module_note.src_loc.byteOffset(module);
+ const byte_offset = try module_note.src_loc.byteOffset();
const loc = std.zig.findLineColumn(source, byte_offset);
const sub_file_path = module_note.src_loc.fileScope().sub_file_path;
note.* = .{
@@ -331,7 +331,7 @@ pub const AllErrors = struct {
};
}
const source = try module_err_msg.src_loc.fileScope().getSource(module);
- const byte_offset = try module_err_msg.src_loc.byteOffset(module);
+ const byte_offset = try module_err_msg.src_loc.byteOffset();
const loc = std.zig.findLineColumn(source, byte_offset);
const sub_file_path = module_err_msg.src_loc.fileScope().sub_file_path;
try errors.append(.{