Support ... in map and struct patterns#7
Open
rodrigues wants to merge 1 commit into
Open
Conversation
`%{...}`, `%{..., k: v}` and `%Struct{...}` raised FunctionClauseError:
match_subset/3 had no clause for the `...` entry. Skip `...` during subset
matching so it imposes no key constraint.
The candidate filter already treated a `...` map/struct as any-arity, so
this completes the feature end to end: `...` matches any map/struct
(including empty), and `%{..., k: v}` matches any map with at least that
entry. Plain `%{k: v}` is unchanged — still an exact key set.
dannote
requested changes
Jul 20, 2026
dannote
left a comment
Collaborator
There was a problem hiding this comment.
The crash fix looks good, but this also codifies an existing inconsistency in map matching.
| describe "map and struct subset matching via search" do | ||
| test "a plain map pattern matches only the exact key set" do | ||
| src = "one = %{a: 1}\ntwo = %{a: 1, b: 2}\n" | ||
| assert [%{}] = ExAST.Patcher.find_all(src, "%{a: 1}") |
Collaborator
There was a problem hiding this comment.
This test locks in behavior that doesn't match the rest of the matcher. Maps are documented as partial, and nested maps already behave that way:
Patcher.find_all("x = %{a: 1, b: 2}", "_ = %{a: 1}")
# one matchThe top-level pattern only looks exact because candidate filtering checks the number of entries. We should fix that inconsistency rather than document it as the intended behavior. The ellipsis crash fix itself looks good.
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.
A literal
...in a map or struct pattern crashed —match_subset/3had no clause for the...node — so%{...},%{..., k: v}and%Struct{...}all raisedFunctionClauseError.The candidate filter already recognized these as any-arity maps/structs, so the feature was half-wired: patterns passed the filter and then blew up in subset matching.
What you can search for now with
mix ex_ast.search:%{role: :admin}%{..., role: :admin}role: :admin%{..., status: s}statuskey, capturing its value%{...}%Struct{...}Plain map patterns (
%{k: v}) are unchanged — still an exact key set. Structs already matched by subset of fields;%Struct{...}just drops the field constraint entirely.Before
After