Skip to content

Conversation

@FnControlOption
Copy link
Contributor

@FnControlOption FnControlOption commented Jul 7, 2023

Add completions for merged error sets

Closes #1130

Screenshot

Implement type resolution for error union payloads

Closes #1245

Enables hover and type resolution for val and err in the following code:

const std = @import("std");

pub fn main() void {
    foo() catch {};
    baz(true);
    baz(false);
}

const Error = error{Foo};

fn foo() Error!void {
    errdefer |err| {
        std.log.err("errdefer - {}", .{@TypeOf(err)});
    }
    return Error.Foo;
}

fn bar(return_error: bool) Error!?i32 {
    if (return_error)
        return Error.Foo;
    return 123;
}

fn baz(comptime return_error: bool) void {
    std.log.info("catch - {}", .{comptime blk: {
        const val = bar(return_error) catch |err| {
            break :blk @TypeOf(err);
        };
        break :blk @TypeOf(val);
    }});

    std.log.info("if - {}", .{comptime blk: {
        if (bar(return_error)) |val| {
            break :blk @TypeOf(val);
        } else |err| {
            break :blk @TypeOf(err);
        }
    }});

    std.log.info("while - {}", .{comptime blk: {
        while (bar(return_error)) |val| {
            break :blk @TypeOf(val);
        } else |err| {
            break :blk @TypeOf(err);
        }
    }});
}

Todo

  • Infer errdefer error type based on the enclosing function's return type
  • Investigate why autocompletion doesn't work for error union capture in empty while block

@FnControlOption FnControlOption changed the title Add completions for merged error sets Error set/union improvements Jul 7, 2023
@FnControlOption FnControlOption changed the title Error set/union improvements Error (set/union) improvements Jul 7, 2023
@leecannon leecannon merged commit b91c86b into zigtools:master Jul 7, 2023
@FnControlOption FnControlOption deleted the merged-error-sets branch July 7, 2023 18:40
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.

zls panic when hovering over captured error from catch Completions aren't provided for merged error sets

2 participants