ziglang / zig

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

Incorrect error message when using a tuple as a sentinel value in an array #18277

Open perillo opened 10 months ago

perillo commented 10 months ago

Zig Version

0.12.0-dev.1821+a38af5f54

Steps to Reproduce and Observed Output

test {
    const array: [3:.{ 1, 2 }]i32 = undefined;
    _ = array;
}

test {
    const tuple = .{ 1, 2 };
    const array: [3:tuple]i32 = undefined;
    _ = array;
}
zig test test.zig
test.zig:2:22: error: type 'i32' does not support array initialization syntax
    const array: [3:.{ 1, 2 }]i32 = undefined;
                    ~^~~~~~~~
test.zig:8:21: error: expected type 'i32', found 'struct{comptime comptime_int = 1, comptime comptime_int = 2}'
    const array: [3:tuple]i32 = undefined;
                    ^~~~~

Expected Output

The two error messages should be the same. The first error message is not incorrect, but it may be confusing to the user.

See also: https://github.com/ziglang/zig/blob/225fe6d/test/cases/compile_errors/array_init_not_supported_on_result_type.zig.

matu3ba commented 10 months ago

"remove non-scalar sentinels from the language".

perillo commented 10 months ago

"remove non-scalar sentinels from the language".

Ironically, I wrote the example after reading that comment, because I have never seen a non scalar sentinel.

Thanks.