JuliaServices / Match.jl

Advanced Pattern Matching for Julia
https://juliaservices.github.io/Match.jl/latest/
Other
240 stars 22 forks source link

Patterns with `getproperty` access broke in v2.0.0 #90

Open jonniediegelman opened 1 year ago

jonniediegelman commented 1 year ago

The 2.0 update broke patterns that look like a.b. Having these patterns is useful for working with EnumX enums because they have to be accessed through their generated module.

With Match@1.2.0:

julia> using EnumX, Match

julia> @enumx Fruit APPLE BANANA PEAR

julia> fruit = Fruit.APPLE
Fruit.APPLE = 0

julia> @match fruit begin
           Fruit.APPLE => 0
           Fruit.BANANA => 1
           Fruit.PEAR => 2
       end
0

With Match@2.0.0:

julia> using EnumX, Match

julia> @enumx Fruit APPLE BANANA PEAR

julia> fruit = Fruit.APPLE
Fruit.APPLE = 0

julia> @match fruit begin
           Fruit.APPLE => 0
           Fruit.BANANA => 1
           Fruit.PEAR => 2
       end
ERROR: LoadError: REPL[5]:2: Unrecognized pattern syntax `Fruit.APPLE`.
Stacktrace:
 [1] error(s::String)
   @ Base ./error.jl:35
 [2] bind_pattern!(location::LineNumberNode, source::Expr, input::Symbol, binder::Match.BinderContext, assigned::Base.ImmutableDict{Symbol, Symbol})
   @ Match ~/.julia/packages/Match/SZDEk/src/binding.jl:408
 [3] bind_case(case_number::Int64, location::LineNumberNode, case::Expr, predeclared_temps::Vector{Any}, binder::Match.BinderContext)
   @ Match ~/.julia/packages/Match/SZDEk/src/binding.jl:580
 [4] build_automaton_core(value::Symbol, source_cases::Vector{Any}, location::LineNumberNode, predeclared_temps::Vector{Any}, binder::Match.BinderContext)
   @ Match ~/.julia/packages/Match/SZDEk/src/match_cases_opt.jl:15
 [5] build_automaton(location::LineNumberNode, mod::Module, value::Any, body::Expr)
   @ Match ~/.julia/packages/Match/SZDEk/src/match_cases_opt.jl:149
 [6] build_deduplicated_automaton
   @ ~/.julia/packages/Match/SZDEk/src/match_cases_opt.jl:158 [inlined]
 [7] handle_match_cases(location::LineNumberNode, mod::Module, value::Symbol, body::Expr)
   @ Match ~/.julia/packages/Match/SZDEk/src/match_cases_opt.jl:477
 [8] var"@match"(__source__::LineNumberNode, __module__::Module, value::Any, cases::Any)
   @ Match ~/.julia/packages/Match/SZDEk/src/matchmacro.jl:114
in expression starting at REPL[5]:1
gafter commented 1 year ago

Please use $(Fruit.APPLE). The escape syntax is used to refer to general expressions or values defined elsewhere.

This was an intentional change in 2.0. I will make sure we document this as a known breaking change.