Skip to content

fix: preserve short-circuit when && or || RHS needs setup#326

Merged
ivov merged 1 commit into
mainfrom
fix-short-circuit-rhs-eval
May 7, 2026
Merged

fix: preserve short-circuit when && or || RHS needs setup#326
ivov merged 1 commit into
mainfrom
fix-short-circuit-rhs-eval

Conversation

@ivov
Copy link
Copy Markdown
Owner

@ivov ivov commented May 7, 2026

Fix && and || evaluating the RHS even when the LHS already decided the result, in cases where the RHS needs setup statements, such as a Result returning call followed by .is_ok(). Previously the emitter hoisted that setup before the operator, defeating Go's native short-circuit; now the RHS setup is wrapped in an IIFE so it runs only when control reaches the RHS.

import "go:fmt"

fn check() -> Result<int, error> {
  fmt.Println("right side ran")
  Ok(1)
}

fn main() {
  if false && check().is_ok() {
    fmt.Println("body")
  }
}

Before this change the program printed right side ran. Now it prints nothing.

@ivov ivov merged commit 4126b50 into main May 7, 2026
12 checks passed
@ivov ivov mentioned this pull request May 7, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 7, 2026

Released in lisette-v0.2.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant