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

Confusing error message in case of missing var/const keyword #12721

Closed
dee0xeed opened this issue Sep 2, 2022 · 0 comments
Closed

Confusing error message in case of missing var/const keyword #12721

dee0xeed opened this issue Sep 2, 2022 · 0 comments
Labels
error message This issue points out an error message that is unhelpful and should be improved.
Milestone

Comments

@dee0xeed
Copy link

dee0xeed commented Sep 2, 2022

Zig Version

0.10.0-dev.3842+36f4f32fa

Steps to Reproduce

Compile this code

const std = @import("std");
const print = std.debug.print;

pub fn main() void {
    z: u32 = 999;
    print("{}\n", .{z});
}

Expected Behavior

Error about missing var or const keyword

Actual Behavior

z.zig:6:8: error: expected 'while', 'for', 'inline', 'suspend', or '{', found 'an identifier'
    z: u32 = 999;
       ^~~

Obviously, the parser treats z: as a label, so this error is quite understandable, but can be a bit confusing, especially for beginners. May be it would be better to have another syntax for labels? Something like this:

label::
label#

or even

::label
#label
$label
@dee0xeed dee0xeed added the bug Observed behavior contradicts documented or intended behavior label Sep 2, 2022
@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 Sep 2, 2022
@Vexu Vexu added this to the 0.11.0 milestone Sep 2, 2022
Vexu added a commit to Vexu/zig that referenced this issue Oct 28, 2022
@Vexu Vexu closed this as completed in 9607bd9 Nov 4, 2022
@andrewrk andrewrk modified the milestones: 0.11.0, 0.10.1 Jan 9, 2023
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