Fix scope creation for label blocks (#1074)

This commit is contained in:
Auguste Rame 2023-03-17 15:02:51 -04:00 committed by GitHub
parent 0aacb76743
commit 3586a7858e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2668,7 +2668,6 @@ fn makeScopeInternal(context: ScopeContext, node_idx: Ast.Node.Index) error{OutO
}, },
.other, .other,
); );
defer context.popScope();
try scopes.items(.decls)[scope_index].putNoClobber(allocator, tree.tokenSlice(first_token), .{ .label_decl = .{ try scopes.items(.decls)[scope_index].putNoClobber(allocator, tree.tokenSlice(first_token), .{ .label_decl = .{
.label = first_token, .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( const scope_index = try context.pushScope(
offsets.nodeToLoc(tree, node_idx), offsets.nodeToLoc(tree, node_idx),
.{ .block = node_idx }, .{ .block = node_idx },
@ -2785,7 +2786,6 @@ fn makeScopeInternal(context: ScopeContext, node_idx: Ast.Node.Index) error{OutO
}, },
.other, .other,
); );
defer context.popScope();
try scopes.items(.decls)[scope_index].putNoClobber(allocator, tree.tokenSlice(label), .{ .label_decl = .{ try scopes.items(.decls)[scope_index].putNoClobber(allocator, tree.tokenSlice(label), .{ .label_decl = .{
.label = label, .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| { if (while_node.payload_token) |payload| {
const scope_index = try context.pushScope( const scope_index = try context.pushScope(
.{ .{
@ -2862,7 +2864,6 @@ fn makeScopeInternal(context: ScopeContext, node_idx: Ast.Node.Index) error{OutO
}, },
.other, .other,
); );
defer context.popScope();
try scopes.items(.decls)[scope_index].putNoClobber(allocator, tree.tokenSlice(label), .{ .label_decl = .{ try scopes.items(.decls)[scope_index].putNoClobber(allocator, tree.tokenSlice(label), .{ .label_decl = .{
.label = label, .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( const scope_index = try context.pushScope(
.{ .{
.start = offsets.tokenToIndex(tree, for_node.payload_token), .start = offsets.tokenToIndex(tree, for_node.payload_token),