Implement ? (question mark) operator for error propagation

The ? operator now desugars expr? to a match expression that unwraps Ok
values and early returns Err values:

  match expr {
      Ok(#ok) => #ok,
      Err(#err) => return Err(#err),
  }

Implementation details:
- Use pre-interned identifiers (#ok, #err) for synthetic variables
- Use pre-interned Ok/Err tag names from CommonIdents
- Create applied_tag patterns for Ok and Err
- Build match branches with proper scope isolation
- Mark synthetic patterns as used to avoid unused variable warnings
- Create e_lookup_local, e_tag, and e_return expressions for branch bodies

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Richard Feldman 2025-11-29 19:25:42 -05:00
parent 2d8f2e3744
commit cc3423a709
No known key found for this signature in database
11 changed files with 176 additions and 444 deletions

View file

@ -0,0 +1,19 @@
app [main!] { pf: platform "./platform/main.roc" }
import pf.Stdout
# Tests pattern matching on string literals in match expressions.
main! = || {
greet("Alice")
greet("Bob")
}
greet = |name| {
message = match name {
"Alice" => "Hello Alice!"
"Bob" => "Hey Bob!"
_ => "Hello stranger!"
}
Stdout.line!(message)
}