MLStyle.jl icon indicating copy to clipboard operation
MLStyle.jl copied to clipboard

dot syntax is not recognized as a pattern

Open Roger-luo opened this issue 2 years ago • 2 comments

MWE:

module Foo
const Bar = 1
end

@match 1 begin
    Foo.Bar => true    
end

causing it fail to support pattern match for singleton variants in https://github.com/Roger-luo/Expronicon.jl/pull/47

Roger-luo avatar Mar 06 '23 18:03 Roger-luo

This requires one to write

@match 1 begin
   &Foo.Bar => true
end

to trigger the evaluation of Foo, but I think Foo.Bar has no ambiguity here, and should just be eval-ed inside the macro. And for example, if it's a function call, currently we will evaluate the dot expression, thus the error is different

caused by: MethodError: no method matching pattern_uncall(::Type{Main.Foo.Baz}, ::MLStyle.MatchImpl.ModuleBoundedEx2tf, ::Vector{Any}, ::Vector{Any}, ::SubArray{Any, 1, Vector{Any}, Tuple{UnitRange{Int64}}, true})
Closest candidates are:

another test case

module Foo

@enum Bar begin
    Baz
    Qux
end

end

@match Foo.Baz begin
    Foo.Baz => true
end

Roger-luo avatar Mar 06 '23 18:03 Roger-luo

seems you are aware of this in #140, what's the issue of support it in the current version?

Roger-luo avatar Mar 06 '23 18:03 Roger-luo