From 881c0cb20b8cbde252ab38dff2c76886c4b72f1d Mon Sep 17 00:00:00 2001 From: Veikka Tuominen Date: Fri, 22 Jul 2022 17:15:15 +0300 Subject: Sema: add default value here note to invalid comptime field store error --- src/Module.zig | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/Module.zig') diff --git a/src/Module.zig b/src/Module.zig index da50fd9ae7..9c4ae69fe6 100644 --- a/src/Module.zig +++ b/src/Module.zig @@ -2704,6 +2704,18 @@ pub const SrcLoc = struct { else => unreachable, } }, + .node_offset_field_default => |node_off| { + const tree = try src_loc.file_scope.getTree(gpa); + const node_tags = tree.nodes.items(.tag); + const parent_node = src_loc.declRelativeToNodeIndex(node_off); + + const full: Ast.full.ContainerField = switch (node_tags[parent_node]) { + .container_field => tree.containerField(parent_node), + .container_field_init => tree.containerFieldInit(parent_node), + else => unreachable, + }; + return nodeToSpan(tree, full.ast.value_expr); + }, } } @@ -3021,6 +3033,9 @@ pub const LazySrcLoc = union(enum) { /// The source location points to the tag type of an union or an enum. /// The Decl is determined contextually. node_offset_container_tag: i32, + /// The source location points to the default value of a field. + /// The Decl is determined contextually. + node_offset_field_default: i32, pub const nodeOffset = if (TracedOffset.want_tracing) nodeOffsetDebug else nodeOffsetRelease; @@ -3098,6 +3113,7 @@ pub const LazySrcLoc = union(enum) { .node_offset_ptr_bitoffset, .node_offset_ptr_hostsize, .node_offset_container_tag, + .node_offset_field_default, => .{ .file_scope = decl.getFileScope(), .parent_decl_node = decl.src_node, -- cgit v1.2.3