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

A typo in "const" keyword causes "error: expected ',' after field" message #15229

Open
Durobot opened this issue Apr 10, 2023 · 2 comments
Open
Labels
error message This issue points out an error message that is unhelpful and should be improved.
Milestone

Comments

@Durobot
Copy link
Sponsor

Durobot commented Apr 10, 2023

Zig Version

0.11.0-dev.2477+2ee328995

Steps to Reproduce and Observed Output

Try to compile the following code:

cost std = @import("std");

pub fn main() void
{
    std.debug.print("Hello, Zig!\n", .{});
}

The following error message is shown:

cost_comp_error.zig:1:6: error: expected ',' after field
cost std = @import("std");
     ^~~

Expected Output

Expected to see an error message stating that cost is an unknown identifier,
or, since .zig files are structs, and the compiler probably considered cost to be the name of the field, "missing : between field cost and type std", and/or "field cost of unknown type std".

@Durobot Durobot added the error message This issue points out an error message that is unhelpful and should be improved. label Apr 10, 2023
@andrewrk andrewrk added this to the 0.13.0 milestone Apr 10, 2023
@mlugg
Copy link
Member

mlugg commented Apr 11, 2023

or, since .zig files are structs, and the compiler probably considered cost to be the name of the field, "missing : between field cost and type std"

This error message is happening because the file is actually being parsed as a tuple type (since tuples are basically just structs), with the first field having type cost. I think it'd be reasonable to disallow files from being tuples, since you can't have declarations on tuples so it seems quite useless; however this issue would still remain on actual struct definitions. Perhaps this should be made a more general error message such as expected field or declaration.

@Durobot
Copy link
Sponsor Author

Durobot commented Apr 14, 2023

.. with the first field having type cost.

You mean, the first field is named cost?

I think it'd be reasonable to disallow files from being tuples

Parts of the standard library rely on this, as far as I can tell, e.g. Allocator.zig -

const Allocator = @This();
. . .
ptr: *anyopaque,
vtable: *const VTable,

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

3 participants