Skip to content

Some inconsistencies when using Or matching #193

@KristofferC

Description

@KristofferC

Typically, if @capture(expr, match_1) matches you would expect @capture(expr, match_1 | match_2) to always also match. This is however not the case. For example:

julia> @capture(:(begin; x = 2;y=3; end), begin body_ end)
true

julia> body
quote
    #= REPL[2]:1 =#
    x = 2
    #= REPL[2]:1 =#
    y = 3
end

matches, but the following

julia> @capture(:(begin; x = 2;y=3; end), begin body_ end | for i_ in iter_ forbody_ end)
false

does not. In addition, it the expression in the block only contains one expression, there will be a match:

julia> @capture(:(begin; x = 2; end), begin body_ end | for i_ in iter_ forbody_ end)
true

julia> body
:(x = 2)

This feels inconsistent to me.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions