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

sane inferred error set name #21406

Closed
wants to merge 2 commits into from

Conversation

DerryAlex
Copy link
Contributor

#21345

const std = @import("std");

fn div(a: i32, b: i32) !i32 {
    return if (b == 0) error.DivisionByZero else @divFloor(a, b);
}

fn wrap(op: anytype, a: i32, b: i32) !i32 {
    return op(i32, a, b);
}

pub fn main() !void {
    const x = std.math.divFloor(i32, 1, 0);
    std.log.debug("{}", .{@TypeOf(x)});
    std.log.debug("{}", .{@TypeOf(std.math.divFloor)});
    const y = div(1, 0);
    std.log.debug("{}", .{@TypeOf(y)});
    std.log.debug("{}", .{@TypeOf(div)});
    const z = wrap(std.math.divFloor, 1, 0);
    std.log.debug("{}", .{@TypeOf(z)});
    std.log.debug("{}", .{@TypeOf(wrap)});
}

Before

debug: @typeInfo(@typeInfo(@TypeOf(math.divFloor__anon_1601)).@"fn".return_type.?).error_union.error_set!i32
debug: fn (comptime type, anytype, anytype) @typeInfo(@typeInfo(@TypeOf(math.divFloor)).@"fn".return_type.?).error_union.error_set!anytype
debug: @typeInfo(@typeInfo(@TypeOf(mytest.div)).@"fn".return_type.?).error_union.error_set!i32
debug: fn (i32, i32) @typeInfo(@typeInfo(@TypeOf(mytest.div)).@"fn".return_type.?).error_union.error_set!i32
debug: @typeInfo(@typeInfo(@TypeOf(mytest.wrap__anon_1658)).@"fn".return_type.?).error_union.error_set!i32
debug: fn (anytype, i32, i32) @typeInfo(@typeInfo(@TypeOf(mytest.wrap)).@"fn".return_type.?).error_union.error_set!i32

After

debug: error{DivisionByZero,Overflow}!i32
debug: fn (comptime type, anytype, anytype) @typeInfo(@typeInfo(@TypeOf(math.divFloor)).@"fn".return_type.?).error_union.error_set!anytype
debug: error{DivisionByZero}!i32
debug: fn (i32, i32) error{DivisionByZero}!i32
debug: error{DivisionByZero,Overflow}!i32
debug: fn (anytype, i32, i32) @typeInfo(@typeInfo(@TypeOf(mytest.wrap)).@"fn".return_type.?).error_union.error_set!i32

@mlugg
Copy link
Member

mlugg commented Sep 15, 2024

This approach is not acceptable. Whether an IES is resolved when a compile error is reported depends on analysis order, which would make errors change based on seemingly arbitrary factors, and would make errors non-deterministic once we introduce threading to semantic analysis.

@mlugg mlugg closed this Sep 15, 2024
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.

3 participants