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

Non meaningful error message on build when type creator contains an error type #11615

Closed
ArnaudValensi opened this issue May 9, 2022 · 0 comments
Labels
bug Observed behavior contradicts documented or intended behavior stage1 The process of building from source via WebAssembly and the C backend.
Milestone

Comments

@ArnaudValensi
Copy link

ArnaudValensi commented May 9, 2022

Zig Version

0.9.1

Steps to Reproduce

Compile the following code.

Note that the code does not build because the CreateType function returns an error type. I think it is expected to not compile.
The problem is that the error message from the compiler does not help to find this issue.

const std = @import("std");

// Here I have mistakenly left a `!`.
pub fn CreateType() !type {
    return struct {};
}

const MyType = CreateType();

const TestType = struct {
    my_type: MyType,
};

pub fn init() TestType {
    return .{
        .my_type = undefined,
    };
}

pub fn main() anyerror!void {
    _ = init();
}
zig build

A repo is available here https://github.com/ArnaudValensi/zig-silent-fail

Expected Behavior

It should display a meaningful error with file and line number.

Actual Behavior

Instead we have this:

$ zig build
Semantic Analysis [499/824] zig-bug...The following command terminated unexpectedly:
/mnt/c/Users/arnau.DESKTOP-2ODO5PA/dev/zig/zig-linux-x86_64-0.9.1/zig build-exe /mnt/c/Users/arnau.DESKTOP-2ODO5PA/dev/zig-bug/src/main.zig --cache-dir /mnt/c/Users/arnau.DESKTOP-2ODO5PA/dev/zig-bug/zig-cache --global-cache-dir /home/arnaud/.cache/zig --name zig-bug --enable-cache
error: the following build command failed with exit code 11:
/mnt/c/Users/arnau.DESKTOP-2ODO5PA/dev/zig-bug/zig-cache/o/5646b52a2268307ffac3274f88ecf9d1/build /mnt/c/Users/arnau.DESKTOP-2ODO5PA/dev/zig/zig-linux-x86_64-0.9.1/zig /mnt/c/Users/arnau.DESKTOP-2ODO5PA/dev/zig-bug /mnt/c/Users/arnau.DESKTOP-2ODO5PA/dev/zig-bug/zig-cache /home/arnaud/.cache/zig
@ArnaudValensi ArnaudValensi added the bug Observed behavior contradicts documented or intended behavior label May 9, 2022
@Vexu Vexu added the stage1 The process of building from source via WebAssembly and the C backend. label May 9, 2022
@Vexu Vexu added this to the 0.12.0 milestone May 9, 2022
Vexu added a commit to Vexu/zig that referenced this issue Mar 28, 2024
Vexu added a commit to Vexu/zig that referenced this issue Mar 28, 2024
Vexu added a commit to Vexu/zig that referenced this issue Mar 28, 2024
Vexu added a commit to Vexu/zig that referenced this issue Mar 28, 2024
@andrewrk andrewrk modified the milestones: 0.15.0, 0.12.0 Mar 28, 2024
Rexicon226 pushed a commit to Rexicon226/zig that referenced this issue Mar 29, 2024
TUSF pushed a commit to TUSF/zig that referenced this issue May 9, 2024
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 stage1 The process of building from source via WebAssembly and the C backend.
Projects
None yet
Development

No branches or pull requests

3 participants