15
8
Fork
You've already forked zig-spec
2

Grammar allows for operations preceding break/continue keywords #55

Open
opened 2024年09月04日 08:54:20 +02:00 by connorjclark · 1 comment
connorjclark commented 2024年09月04日 08:54:20 +02:00 (Migrated from github.com)
Copy link
while(true){!break;}while(true){--break;}while(true){1+break;}

All three pass the grammar as defined in grammar.y, and I believe the first two have no impact on actual zig compilation results. The third one fails the zig compiler due to unreachable code (it considers the 1 + to be unreachable)

PrimaryExpr is the relevant rule. All of the binary and unary operations coming in from PrefixExpr on the left-hand-side is what allows for this unexpected grammar.

```zig while (true) { !break; } while (true) { --break; } while (true) { 1 + break; } ``` All three pass the grammar as defined in `grammar.y`, and I believe the first two have no impact on actual zig compilation results. The third one fails the zig compiler due to unreachable code (it considers the `1 +` to be unreachable) `PrimaryExpr` is the relevant [rule](https://github.com/ziglang/zig-spec/blob/75129c7a34010ead828055c26a6d41d1516faa97/grammar/grammar.y#L99). All of the binary and unary operations coming in from `PrefixExpr` on the left-hand-side is what allows for this unexpected grammar.
gooncreeper commented 2025年03月16日 21:09:34 +01:00 (Migrated from github.com)
Copy link

I believe this is correct since break evaluates to a value of type noreturn. It should actually probably consider all three of them to be unreachable, so I guess there is a bug there.

I believe this is correct since break evaluates to a value of type noreturn. It should actually probably consider all three of them to be unreachable, so I guess there is a bug there.
alexrp unlocked this conversation 2025年12月13日 01:58:38 +01:00
Sign in to join this conversation.
No Branch/Tag specified
master
sync
disorganized-spec-chunks
No results found.
Labels
Clear labels
bounty
https://ziglang.org/news/announcing-donor-bounties
bug
Observed behavior contradicts documented or intended behavior.
contributor-friendly
This issue is limited in scope and/or knowledge of project internals.
downstream
An issue with a third-party project that uses this project.
enhancement
Solving this issue will likely involve adding new logic or components to the codebase.
infra
An issue related to project infrastructure, e.g. continuous integration.
optimization
A task to improve performance and/or resource usage.
question
No questions on the issue tracker; use a community space instead.
regression
Something that used to work in a previous version stopped working
upstream
An issue with a third-party project that this project uses.
use case
Describes a real use case that is difficult or impossible, but does not propose a solution.
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
ziglang/zig-spec#55
Reference in a new issue
ziglang/zig-spec
No description provided.
Delete branch "%!s()"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?