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

Invalid token in commented code #21126

Closed
bobf opened this issue Aug 18, 2024 · 2 comments
Closed

Invalid token in commented code #21126

bobf opened this issue Aug 18, 2024 · 2 comments
Labels
bug Observed behavior contradicts documented or intended behavior

Comments

@bobf
Copy link
Contributor

bobf commented Aug 18, 2024

Zig Version

0.14.0-dev.1166+bb7050106

Steps to Reproduce and Observed Behavior

Compiling this build.zig:

const std = @import("std");

pub fn build(b: *std.Build) !void {
    const target = b.standardTargetOptions(.{});
    const optimize = b.standardOptimizeOption(.{});

    const dep_opts = .{ .target = target, .optimize = optimize };
    const metrics_module = b.dependency("metrics", dep_opts).module("metrics");
    const websocket_module = b.dependency("websocket", dep_opts).module("websocket");

    // const websocket_module = b.addModule("websocket", .{
    // 	.source_file = .{.path = "../websocket.zig/src/websocket.zig"}
    // });

    const httpz_module = b.addModule("httpz", .{
        .root_source_file = b.path("src/httpz.zig"),
        .imports = &.{
            .{ .name = "metrics", .module = metrics_module },
            .{ .name = "websocket", .module = websocket_module },
        },
    });
    {
        const options = b.addOptions();
        options.addOption(bool, "force_blocking", false);
        httpz_module.addOptions("build", options);
    }

    {
        // demo
        const exe = b.addExecutable(.{
            .name = "http.zig demo",
            .root_source_file = b.path("example/main.zig"),
            .target = target,
            .optimize = optimize,
        });
        exe.root_module.addImport("httpz", httpz_module);
        exe.root_module.addImport("metrics", metrics_module);
        exe.root_module.addImport("websocket", websocket_module);
        b.installArtifact(exe);

        const run_cmd = b.addRunArtifact(exe);
        run_cmd.step.dependOn(b.getInstallStep());
        if (b.args) |args| {
            run_cmd.addArgs(args);
        }
        const run_step = b.step("run", "Run the app");
        run_step.dependOn(&run_cmd.step);
    }

    {
        // run tests in nonblocking mode (only meaningful where epoll/kqueue is supported)
        const tests = b.addTest(.{
            .root_source_file = b.path("src/httpz.zig"),
            .target = target,
            .optimize = optimize,
            .test_runner = b.path("test_runner.zig"),
        });
        tests.linkLibC();
        const options = b.addOptions();
        options.addOption(bool, "force_blocking", false);
        tests.root_module.addOptions("build", options);
        tests.root_module.addImport("metrics", metrics_module);
        tests.root_module.addImport("websocket", websocket_module);
        const run_test = b.addRunArtifact(tests);
        run_test.has_side_effects = true;

        const test_step = b.step("test", "Run tests");
        test_step.dependOn(&run_test.step);
    }

    {
        // run tests in blocking mode
        const tests = b.addTest(.{
            .root_source_file = b.path("src/httpz.zig"),
            .target = target,
            .optimize = optimize,
            .test_runner = b.path("test_runner.zig"),
        });
        tests.linkLibC();
        const options = b.addOptions();
        options.addOption(bool, "force_blocking", true);
        tests.root_module.addOptions("build", options);

        tests.root_module.addImport("metrics", metrics_module);
        tests.root_module.addImport("websocket", websocket_module);
        const run_test = b.addRunArtifact(tests);
        run_test.has_side_effects = true;

        const test_step = b.step("test_blocking", "Run tests");
        test_step.dependOn(&run_test.step);
    }
}

Gives this error:

/home/bob/.cache/zig/p/122089946af5ba1cdfae3f515f0fa1c96327f42a462515fbcecc719fe94fab38d9b8/build.zig:12:5: error: expected statement, found 'invalid token'
    //  .source_file = .{.path = "../websocket.zig/src/websocket.zig"}
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

@karlseguin FYI

Expected Behavior

Compiler does not error when evaluating commented code.

@bobf bobf added the bug Observed behavior contradicts documented or intended behavior label Aug 18, 2024
@castholm
Copy link
Contributor

Duplicate of #20900.

This it not a bug but rather just a very poor and unhelpful error message; there's a tab character in the line comment (replaced with a control picture for clarity):

    // ␉.source_file = .{.path = "../websocket.zig/src/websocket.zig"}

Tabs in comments have always been in violation of the spec (ziglang/zig-spec#38) but only recently was the tokenizer updated to conform to the spec, see #20885.

@Vexu Vexu closed this as not planned Won't fix, can't repro, duplicate, stale Aug 18, 2024
@bobf
Copy link
Contributor Author

bobf commented Aug 18, 2024

@castholm Thanks for the explanation. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior
Projects
None yet
Development

No branches or pull requests

3 participants