Skip to content

feat(compiler): accept truthy filter predicates - #153

Merged
jimmyhmiller merged 7 commits into
mainfrom
split/filter-truthy-predicate
Aug 17, 2026
Merged

feat(compiler): accept truthy filter predicates#153
jimmyhmiller merged 7 commits into
mainfrom
split/filter-truthy-predicate

Conversation

@jimmyhmiller

Copy link
Copy Markdown
Contributor

Summary

  • accept statically representable non-boolean Array.prototype.filter predicate results and lower them through ToBoolean
  • retain a clear fence for void predicates, including static, island-backed, and checked-dynamic arrays
  • add differential and diagnostic coverage for truthiness and the unsupported void ABI

Validation

  • pnpm exec vitest run tests/harness/diagnostics.test.ts
  • pnpm exec vitest run tests/harness/differential.test.ts --testNamePattern "2683-filter-truthy-predicate"
  • pnpm exec vitest run packages/compiler/test/ts7/order-parity.test.ts
  • final reviewer pass: no blocking findings

jimmyhmiller and others added 6 commits August 14, 2026 10:27
`.filter(fn)` required the callback to return exactly bool. JS applies
ToBoolean to whatever the predicate answers, so `xs.filter((s) => s)` — the
idiomatic drop-the-falsy — was refused for no semantic reason.

The filter loop now wraps the call in the same toBool an `if` statement would
apply. A bool answer is unchanged and emits identical IR. A union answer
routes through its interned per-arm truthy helper, requested at the call site
where a real node exists for the diagnostic. A unit-only answer is constantly
falsy, and the call still runs for its effects.

The kinds with no native ToBoolean keep the fence: void has no value at all,
and dyn/jsval/caught truthiness needs the embedded engine.

Verified against Node: filtering strings, numbers, and a
`(string | undefined)[]` all print identically in both.

Diagnostics 100, filter corpus 9 across both
backends.
@vercel

vercel Bot commented Aug 14, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
scriptc Ready Ready Preview Aug 17, 2026 4:04pm

Comment thread packages/compiler/src/frontend/lowering/lower-containers.ts Outdated
@jimmyhmiller
jimmyhmiller merged commit 729f809 into main Aug 17, 2026
12 checks passed
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.

2 participants