From 3586a7858e1bc6d9cd430f04752c248d37d5137c Mon Sep 17 00:00:00 2001 From: Auguste Rame <19855629+SuperAuguste@users.noreply.github.com> Date: Fri, 17 Mar 2023 15:02:51 -0400 Subject: [PATCH] Fix scope creation for label blocks (#1074) --- src/analysis.zig | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/analysis.zig b/src/analysis.zig index ad600cc..edbe478 100644 --- a/src/analysis.zig +++ b/src/analysis.zig @@ -2668,7 +2668,6 @@ fn makeScopeInternal(context: ScopeContext, node_idx: Ast.Node.Index) error{OutO }, .other, ); - defer context.popScope(); try scopes.items(.decls)[scope_index].putNoClobber(allocator, tree.tokenSlice(first_token), .{ .label_decl = .{ .label = first_token, @@ -2676,6 +2675,8 @@ fn makeScopeInternal(context: ScopeContext, node_idx: Ast.Node.Index) error{OutO } }); } + defer if (token_tags[first_token] == .identifier) context.popScope(); + const scope_index = try context.pushScope( offsets.nodeToLoc(tree, node_idx), .{ .block = node_idx }, @@ -2785,7 +2786,6 @@ fn makeScopeInternal(context: ScopeContext, node_idx: Ast.Node.Index) error{OutO }, .other, ); - defer context.popScope(); try scopes.items(.decls)[scope_index].putNoClobber(allocator, tree.tokenSlice(label), .{ .label_decl = .{ .label = label, @@ -2793,6 +2793,8 @@ fn makeScopeInternal(context: ScopeContext, node_idx: Ast.Node.Index) error{OutO } }); } + defer if (while_node.label_token != null) context.popScope(); + if (while_node.payload_token) |payload| { const scope_index = try context.pushScope( .{ @@ -2862,7 +2864,6 @@ fn makeScopeInternal(context: ScopeContext, node_idx: Ast.Node.Index) error{OutO }, .other, ); - defer context.popScope(); try scopes.items(.decls)[scope_index].putNoClobber(allocator, tree.tokenSlice(label), .{ .label_decl = .{ .label = label, @@ -2870,6 +2871,8 @@ fn makeScopeInternal(context: ScopeContext, node_idx: Ast.Node.Index) error{OutO } }); } + defer if (for_node.label_token != null) context.popScope(); + const scope_index = try context.pushScope( .{ .start = offsets.tokenToIndex(tree, for_node.payload_token),