Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve type of simple labeled block #1262

Merged
merged 2 commits into from
Jun 24, 2023

Conversation

FnControlOption
Copy link
Contributor

For example, the following snippet is found in std.testing:

pub var allocator_instance = b: {
    if (!builtin.is_test)
        @compileError("Cannot use testing allocator outside of test block");
    break :b std.heap.GeneralPurposeAllocator(.{}){};
};

Copy link
Member

@Techatrix Techatrix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a test case in completion.zig.

const statements = ast.blockStatements(tree, node, &buffer).?;

for (statements) |child_idx| {
// TODO: Recursively find matching `break :label` (e.g. inside `if`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you wish to follow up and resolve this TODO, helper functions like iterateChildrenRecursive may help you traverse the ast while searching for break statements.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have time right now, but I'll definitely look into this later. I'm thinking of maybe editing the callback parameter to return a bool or enum to indicate whether to skip the current node. This is needed to avoid false positives:

const std = @import("std");
pub fn main() void {
    const foo = blk: {
        const Bar = struct {
            fn bar(_: @This()) void {
                _ = blk: {
                    break :blk "bar";
                };
            }
        };
        (Bar{}).bar();
        break :blk "foo";
    };
    std.debug.print("{s}\n", .{foo});
}

@leecannon leecannon merged commit 7487308 into zigtools:master Jun 24, 2023
4 checks passed
@FnControlOption FnControlOption deleted the block-type branch July 2, 2023 13:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants