[GH-ISSUE #7678] Shader packs: #if evaluates the short-circuited side of && / ||, so a guarded division by zero is an error #3328

Open
opened 2026-11-03 04:07:34 +07:00 by bsakaguchi · 3 comments
Owner

Originally created by @ClickingMaster on GitHub (Nov 2, 2026).
Original GitHub issue: https://github.com/horizon-rust/horizon/issues/7678

Originally assigned to: @ClickingMaster on GitHub.

🤖 Filed by ClickingMaster's AI agent (Claude Code, Claude Sonnet 5.5), not by ClickingMaster personally.

Where: crates/horizon-shaders/src/condition.rs, Parser::binary / apply ("/" | "%" if b == 0.0 => Err("division by zero")).

Problem: && and || in a shader pack's #if evaluate both operands, so a guarded division by zero is an error. The C preprocessor and GL drivers do not evaluate the operand a &&/|| short-circuits past, so the guard is the idiomatic way to write it.

Example: with #define AMOUNT 0:

#if AMOUNT != 0 && 100 / AMOUNT > 5

Expected: false, no diagnostic (100 / AMOUNT is never evaluated). Actual: eval_condition returns Err("division by zero"), the #if is "read as false" with a warning. Same for AMOUNT == 0 || 100 / AMOUNT > 5, which should be true but reads as false, so the pack loses that section.

Fix: parse the skipped operand with division errors suppressed.

Originally created by @ClickingMaster on GitHub (Nov 2, 2026). Original GitHub issue: https://github.com/horizon-rust/horizon/issues/7678 Originally assigned to: @ClickingMaster on GitHub. > 🤖 Filed by ClickingMaster's AI agent (Claude Code, Claude Sonnet 5.5), not by ClickingMaster personally. **Where:** `crates/horizon-shaders/src/condition.rs`, `Parser::binary` / `apply` (`"/" | "%" if b == 0.0 => Err("division by zero")`). **Problem:** `&&` and `||` in a shader pack's `#if` evaluate both operands, so a guarded division by zero is an error. The C preprocessor and GL drivers do not evaluate the operand a `&&`/`||` short-circuits past, so the guard is the idiomatic way to write it. **Example:** with `#define AMOUNT 0`: ```glsl #if AMOUNT != 0 && 100 / AMOUNT > 5 ``` Expected: false, no diagnostic (`100 / AMOUNT` is never evaluated). Actual: `eval_condition` returns `Err("division by zero")`, the `#if` is "read as false" with a warning. Same for `AMOUNT == 0 || 100 / AMOUNT > 5`, which should be true but reads as false, so the pack loses that section. **Fix:** parse the skipped operand with division errors suppressed.
Author
Owner

@ClickingMaster commented on GitHub (Nov 2, 2026):

🤖 Agent: /claim

<!-- gh-comment-id:6586144754 --> @ClickingMaster commented on GitHub (Nov 2, 2026): 🤖 Agent: /claim
Author
Owner

@ClickingMaster commented on GitHub (Nov 2, 2026):

🤖 Agent: /unclaim

<!-- gh-comment-id:6586225423 --> @ClickingMaster commented on GitHub (Nov 2, 2026): 🤖 Agent: /unclaim
Author
Owner

@ClickingMaster commented on GitHub (Nov 2, 2026):

🤖 Agent: /claim

<!-- gh-comment-id:6587024523 --> @ClickingMaster commented on GitHub (Nov 2, 2026): 🤖 Agent: /claim
Sign in to join this conversation.
No milestone
No project
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
horizon-rust/horizon#3328
No description provided.