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

Wrong Error Message for coercing an anonymous tuple to a struct #20752

Open
Serif-7 opened this issue Jul 23, 2024 · 1 comment
Open

Wrong Error Message for coercing an anonymous tuple to a struct #20752

Serif-7 opened this issue Jul 23, 2024 · 1 comment
Labels
error message This issue points out an error message that is unhelpful and should be improved.
Milestone

Comments

@Serif-7
Copy link

Serif-7 commented Jul 23, 2024

Zig Version

0.12.0

Steps to Reproduce and Observed Behavior

const std = @import("std");

pub fn main() !void {
    var r: Range = foo(10, 20);
    _ = &r;
}

const Range = struct {
    start: usize,
    len: usize,
};

pub fn foo(start: usize, length: usize) struct { usize, usize } {
    return .{ start, length };
}

This produces the following error:

test.zig:4:23: error: no field named 'd' in struct 'test.Range'
    var r: Range = foo(10, 20);
                   ~~~^~~~~~~~
test.zig:8:15: note: struct declared here
const Range = struct {
              ^~~~~~

This is of course the wrong error.

Expected Behavior

The correct error should be something like this (syntax changed to induce the proper error):

test.zig:5:34: error: type 'test.Range' does not support array initialization syntax
    var r: Range = .{ foo(10, 20).start, foo(10, 20).length };
                      ~~~~~~~~~~~^~~~~~
@Serif-7 Serif-7 added the bug Observed behavior contradicts documented or intended behavior label Jul 23, 2024
@Vexu
Copy link
Member

Vexu commented Jul 23, 2024

Incorrect error message fixed in #19620 but it could still be better

a.zig:18:23: error: no field named '0' in struct 'a.Range'
    var r: Range = foo(10, 20);
                   ~~~^~~~~~~~
a.zig:22:15: note: struct declared here
const Range = struct {
              ^~~~~~

@Vexu Vexu added error message This issue points out an error message that is unhelpful and should be improved. and removed bug Observed behavior contradicts documented or intended behavior labels Jul 23, 2024
@Vexu Vexu added this to the 0.16.0 milestone Jul 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
error message This issue points out an error message that is unhelpful and should be improved.
Projects
None yet
Development

No branches or pull requests

2 participants