aboutsummaryrefslogtreecommitdiff
path: root/src/Sema.zig
diff options
context:
space:
mode:
authorVeikka Tuominen <git@vexu.eu>2022-07-15 16:05:06 +0300
committerVeikka Tuominen <git@vexu.eu>2022-07-15 16:06:16 +0300
commitcf207df5926c2f303ad92069e44bec51bfa44148 (patch)
tree093fb27867621e32699bd7fdd179b4e045846917 /src/Sema.zig
parent1463144fc88550ba1dca3888acdcdd4903781222 (diff)
downloadzig-cf207df5926c2f303ad92069e44bec51bfa44148.tar.gz
zig-cf207df5926c2f303ad92069e44bec51bfa44148.zip
Module: improve source spans for initializers and var types
```zig const U = union { foo: u32, bar: u32 }; test { var a = U{ .foo = 1213, .bar = 1123 }; _ = a; } test { var a: (123 + 5238094) = 0; _ = a; } ``` before: ``` :30: note: additional initializer here var a = U{ .foo = 1213, .bar = 1123 }; ^~~ :12: error: expected type 'type', found 'comptime_int' var a: (123 + 5238094) = 0; ^ ``` after: ``` :30: note: additional initializer here var a = U{ .foo = 1213, .bar = 1123 }; ~^~~~~~~~~~ :12: error: expected type 'type', found 'comptime_int' var a: (123 + 5238094) = 0; ^~~~~~~~~~~~~~~ ```
Diffstat (limited to 'src/Sema.zig')
-rw-r--r--src/Sema.zig16
1 files changed, 8 insertions, 8 deletions
diff --git a/src/Sema.zig b/src/Sema.zig
index 29840820d0..305210517a 100644
--- a/src/Sema.zig
+++ b/src/Sema.zig
@@ -3403,7 +3403,7 @@ fn validateUnionInit(
for (instrs[1..]) |inst| {
const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
- const inst_src: LazySrcLoc = .{ .node_offset_back2tok = inst_data.src_node };
+ const inst_src: LazySrcLoc = .{ .node_offset_initializer = inst_data.src_node };
try sema.errNote(block, inst_src, msg, "additional initializer here", .{});
}
try sema.addDeclaredHereNote(msg, union_ty);
@@ -3421,7 +3421,7 @@ fn validateUnionInit(
const field_ptr = instrs[0];
const field_ptr_data = sema.code.instructions.items(.data)[field_ptr].pl_node;
- const field_src: LazySrcLoc = .{ .node_offset_back2tok = field_ptr_data.src_node };
+ const field_src: LazySrcLoc = .{ .node_offset_initializer = field_ptr_data.src_node };
const field_ptr_extra = sema.code.extraData(Zir.Inst.Field, field_ptr_data.payload_index).data;
const field_name = sema.code.nullTerminatedString(field_ptr_extra.field_name_start);
const field_index = try sema.unionFieldIndex(block, union_ty, field_name, field_src);
@@ -3523,7 +3523,7 @@ fn validateStructInit(
for (instrs) |field_ptr| {
const field_ptr_data = sema.code.instructions.items(.data)[field_ptr].pl_node;
- const field_src: LazySrcLoc = .{ .node_offset_back2tok = field_ptr_data.src_node };
+ const field_src: LazySrcLoc = .{ .node_offset_initializer = field_ptr_data.src_node };
const field_ptr_extra = sema.code.extraData(Zir.Inst.Field, field_ptr_data.payload_index).data;
struct_ptr_zir_ref = field_ptr_extra.lhs;
const field_name = sema.code.nullTerminatedString(field_ptr_extra.field_name_start);
@@ -3531,7 +3531,7 @@ fn validateStructInit(
if (found_fields[field_index] != 0) {
const other_field_ptr = found_fields[field_index];
const other_field_ptr_data = sema.code.instructions.items(.data)[other_field_ptr].pl_node;
- const other_field_src: LazySrcLoc = .{ .node_offset_back2tok = other_field_ptr_data.src_node };
+ const other_field_src: LazySrcLoc = .{ .node_offset_initializer = other_field_ptr_data.src_node };
const msg = msg: {
const msg = try sema.errMsg(block, field_src, "duplicate field", .{});
errdefer msg.destroy(gpa);
@@ -3606,7 +3606,7 @@ fn validateStructInit(
field: for (found_fields) |field_ptr, i| {
if (field_ptr != 0) {
const field_ptr_data = sema.code.instructions.items(.data)[field_ptr].pl_node;
- const field_src: LazySrcLoc = .{ .node_offset_back2tok = field_ptr_data.src_node };
+ const field_src: LazySrcLoc = .{ .node_offset_initializer = field_ptr_data.src_node };
// Determine whether the value stored to this pointer is comptime-known.
const field_ty = struct_ty.structFieldType(i);
@@ -13999,14 +13999,14 @@ fn zirStructInit(
extra_index = item.end;
const field_type_data = zir_datas[item.data.field_type].pl_node;
- const field_src: LazySrcLoc = .{ .node_offset_back2tok = field_type_data.src_node };
+ const field_src: LazySrcLoc = .{ .node_offset_initializer = field_type_data.src_node };
const field_type_extra = sema.code.extraData(Zir.Inst.FieldType, field_type_data.payload_index).data;
const field_name = sema.code.nullTerminatedString(field_type_extra.name_start);
const field_index = try sema.structFieldIndex(block, resolved_ty, field_name, field_src);
if (field_inits[field_index] != .none) {
const other_field_type = found_fields[field_index];
const other_field_type_data = zir_datas[other_field_type].pl_node;
- const other_field_src: LazySrcLoc = .{ .node_offset_back2tok = other_field_type_data.src_node };
+ const other_field_src: LazySrcLoc = .{ .node_offset_initializer = other_field_type_data.src_node };
const msg = msg: {
const msg = try sema.errMsg(block, field_src, "duplicate field", .{});
errdefer msg.destroy(gpa);
@@ -14028,7 +14028,7 @@ fn zirStructInit(
const item = sema.code.extraData(Zir.Inst.StructInit.Item, extra.end);
const field_type_data = zir_datas[item.data.field_type].pl_node;
- const field_src: LazySrcLoc = .{ .node_offset_back2tok = field_type_data.src_node };
+ const field_src: LazySrcLoc = .{ .node_offset_initializer = field_type_data.src_node };
const field_type_extra = sema.code.extraData(Zir.Inst.FieldType, field_type_data.payload_index).data;
const field_name = sema.code.nullTerminatedString(field_type_extra.name_start);
const field_index = try sema.unionFieldIndex(block, resolved_ty, field_name, field_src);