• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

moonbitlang / core / 5632

28 Jul 2026 07:24AM UTC coverage: 90.461% (-0.8%) from 91.255%
5632

push

github

bobzhang
refactor: replace fall-through `match` with `guard ... is`

Rewrites the two-arm `match x { Pat => action; _ => () }` shape as
`guard x is Pat else { () }` followed by the action, which removes a
level of nesting and puts the interesting branch at statement level.

7 sites: `diff/diff.mbt`, `builtin/iterator.mbt`, and the `json` tests.

Found with moongrep, generalising past the `Option`-specific shape:

    moongrep scan --pattern 'match $(x:exp) {
      $(p1:pat) => $(action:exp)
      $(p2:pat) => ()
    }'

`$(pN:pat)` captures whole pattern ASTs, so it matches `Some(_)/None`,
`Number(n, ..)/_` and `['-', ..]/_` alike — 11 sites, against 5 for the
literal `Some($(p:pat))`/`None` shape.

**The rewrite is not unconditional.** `guard` skips the rest of the
enclosing block when it fails, whereas the `() ` arm falls through and
lets execution continue. So it is only equivalent when the `match` is
the *last* statement in its block. Four sites are left as-is:

- `diff/diff.mbt:160`, `diff/diff.mbt:222` and
  `string/internal/regex_parser/parser.mbt:160` are mid-block — code
  follows the `match`. Converting them would silently skip that code on
  the fall-through path. These want `if x is Pat { action }`, not
  `guard`, and are left alone here.
- `argparse/parser_validate.mbt:266` is in tail position and converts
  correctly, but its two-constructor or-pattern makes the `guard` header
  wrap across four lines and read worse than the `match`. Reverted on
  readability grounds.

Comments that annotated the `() ` arm are moved onto the `else` branch,
which is where that fall-through now lives.

Tests pass on wasm-gc, js and native; `moon info` reports no `.mbti`
change.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

4 of 4 new or added lines in 2 files covered. (100.0%)

208 existing lines in 8 files now uncovered.

15752 of 17413 relevant lines covered (90.46%)

174054.61 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

21.28
/encoding/utf8/encode_nonjs.mbt


Source Not Available

STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc