Skip to content

Gleam: | alternatives in match arm patterns (ILO-411)#709

Merged
danieljohnmorris merged 2 commits into
mainfrom
feature/match-or-alternatives
May 22, 2026
Merged

Gleam: | alternatives in match arm patterns (ILO-411)#709
danieljohnmorris merged 2 commits into
mainfrom
feature/match-or-alternatives

Conversation

@danieljohnmorris
Copy link
Copy Markdown
Collaborator

Summary

  • Adds Pattern::Or(Vec<Pattern>) to the AST for pipe-separated match alternatives
  • Parser: parse_match_arm now collects |-separated patterns into Pattern::Or
  • VM: compiles Pattern::Or by checking each alternative; matches if any hits
  • Interpreter, verifier, formatter, and Python codegen all handle the new variant

Example

?x{"a"|"b":"found";_:"miss"}

Matches both "a" and "b" with the same arm body. Three or more alternatives are also supported: 1|2|3:"low".

Test plan

  • vm_or_pattern_first_alt_matches — first alternative fires
  • vm_or_pattern_second_alt_matches — second alternative fires
  • vm_or_pattern_no_alt_matches — falls through to wildcard
  • vm_or_pattern_three_alts — three alternatives, middle one matches
  • parse_match_or_pattern_two_alts — AST shape correct for 2 alts
  • parse_match_or_pattern_three_alts — AST shape correct for 3 alts
  • Full test suite: 3373 + 399 tests pass, 0 failures

🤖 Generated with Claude Code

Daniel Morris and others added 2 commits May 22, 2026 08:58
`?x{"a"|"b":"found";_:"miss"}` now parses and executes correctly —
a single arm fires when the subject equals any of the pipe-separated
patterns. Implemented across parser, AST, VM codegen, interpreter,
formatter, Python codegen, and verifier.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@codecov
Copy link
Copy Markdown

codecov Bot commented May 22, 2026

Codecov Report

❌ Patch coverage is 58.57988% with 70 lines in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/codegen/python.rs 0.00% 33 Missing ⚠️
src/vm/mod.rs 78.49% 20 Missing ⚠️
src/interpreter/mod.rs 0.00% 6 Missing ⚠️
src/parser/mod.rs 81.25% 6 Missing ⚠️
src/verify.rs 0.00% 4 Missing ⚠️
src/codegen/fmt.rs 0.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@danieljohnmorris danieljohnmorris merged commit ffb4131 into main May 22, 2026
10 of 11 checks passed
@danieljohnmorris danieljohnmorris deleted the feature/match-or-alternatives branch May 22, 2026 08:19
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