ziglang / zig

General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.
https://ziglang.org
MIT License
34.46k stars 2.52k forks source link

inferred error sets have strippable identity (missing documentation?) #20862

Open rohlem opened 2 months ago

rohlem commented 2 months ago

Zig Version

0.14.0-dev.617+208baa37c

Steps to Reproduce and Observed Behavior

Repro:

fn foo() !void {}
comptime {
    const A = @typeInfo(@TypeOf(foo())).ErrorUnion.error_set;
    const B = error{};
    @compileLog(A == B); //false
    @compileLog((A || error{}) == B); //true
    @compileLog(@Type(@typeInfo(A)) == B); //true
}

Expected Behavior

I didn't know that inferred error sets have identity that makes them compare unequal to all other error sets - it's not currently mentioned in their langref section.

When looking for previous issues on this I found that all error sets used to have identity, which changed with implementing https://github.com/ziglang/zig/issues/11022 . A comment there documents that "we're experimenting" with inferred error sets having identity "to ease the implementation of the language specification. It's problematic to make type equality force error set resolution." If that's still the current stance on the issue, I can accept that it just needs to be documented.

mlugg commented 2 months ago

Yep, status quo is intended, and this is just missing documentation.