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

comptime prefix being treated as comptime block causing inconsistent treatment of unreachable code formulation #20698

Open
InKryption opened this issue Jul 20, 2024 · 1 comment
Labels
bug Observed behavior contradicts documented or intended behavior error message This issue points out an error message that is unhelpful and should be improved. frontend Tokenization, parsing, AstGen, Sema, and Liveness.
Milestone

Comments

@InKryption
Copy link
Contributor

Zig Version

0.14.0-dev.224+95d9292a7

Steps to Reproduce and Observed Behavior

Consider this code, which yields an unreachable code error:

@compileError("foo");
return;

and then consider this extremely similar, but subtly different, non-erroring code:

comptime @compileError("foo");
return;

it would appear that the ast-check responsible for unreachable control flow treats comptime expr; expr; the same as { expr; } expr;.

While this almost makes sense if you squint your brain, it's very unintuitive and was directly described as a bug by @mlugg, who requested this be made into a bug report.

Expected Behavior

Both snippets should error.

@InKryption InKryption added the bug Observed behavior contradicts documented or intended behavior label Jul 20, 2024
@mlugg mlugg added this to the 0.14.0 milestone Jul 20, 2024
@mlugg mlugg added frontend Tokenization, parsing, AstGen, Sema, and Liveness. error message This issue points out an error message that is unhelpful and should be improved. labels Jul 20, 2024
@mlugg
Copy link
Member

mlugg commented Jul 20, 2024

My interpretation of this bug is that a simple block shouldn't elide the "unreachable code" error. i.e. { @compileError("foo"); }; return; should also be an error. It seems to me that this is the intended behavior based upon the fact that we use e.g.

if (true) {
    return error.SkipZigTest;
}

over

{
    return error.SkipZigTest;
}

An unlabeled block whose end is guaranteed to be unreachable should propagate this "unreachable code" information to the parent scope.

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 error message This issue points out an error message that is unhelpful and should be improved. frontend Tokenization, parsing, AstGen, Sema, and Liveness.
Projects
None yet
Development

No branches or pull requests

2 participants