Repository navigation
Unified patterns; is with patterns and bindings; defer expr; match x is Enum - #86
Merged
Merged
Conversation
…n and binds in if/while; defer expr; match x is Enum
- let, parameters and for-in take nested patterns; match patterns take defaults and object rest
- let patterns only take values apart; testing patterns there is a compile error
- v is P matches any pattern (bare names are types, constants and unit variants are values)
- is in an if or while condition binds variables for the body and the right of &&
- defer expr; a braced single expression is an error
- match x is Enum { Variant => ... } names variants bare, checks coverage
- pattern code moves to compile_pattern.go and resolve_pattern.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
let, parameters andfortake nested patterns (let { user: { name, tags: [first, ...more] } } = r;);matchpatterns take defaults and object rest ({ name, role = "member", ...extra },[cmd, target = "."]). A key may repeat to bind and take apart ({ pos, pos: { x } }).letpatterns only take values apart; literals, ranges,|or types there are a compile error.v is Ptakes any pattern:x is 1..10,x is "a" | "b",r is { status: 200..300 },S.A is S.A,x is LIMIT. Bare names are types, unless they name a constant or a unit variant.iforwhilecondition,isbinds:if r is { status: 200, body } && body { ... },while q.pop() is { id } { ... },name is Pbinds the whole value. Binding elsewhere, after!isor||is a compile error.defer expr;;defer { single; }is an error (one way).match s is Status { Pending => ..., Paid | Shipped => ..., Card { brand } => ... }: bare variants, coverage checked, unknown names caught, non-Statusvalue is a no-match error.Notes
p is 1was a runtime TypeError, now a literal test (false).istype error points at the type now.compile_pattern.goandresolve_pattern.go;compile_expr.goandresolver.goshrank below their previous sizes.isis unchanged; conditions withisnow compile toJMPNOTTYPEchains.Tests
New scripts in
test/destructure,test/match,test/is,test/defer; docs examples re-run; 90s fuzz clean.