Open cscherrer opened 5 years ago
Hi! Thank you for your feedback here! I have to say sorry for now the error message does make some mess. Some people has requested a better error reporting, as a result, I have raised the priority of this task.
This might take some time, but I promise it'll be done until the mid-May.
Note: Refactoring and improving error messages might cause some changes of MLStyle's low level implementation. Don't use def_pattern
to define your own patterns if you don't want to get a compatibility issue in the future, and anything noted in the documents won't be influenced.
Would you like to try the master branch out? I've improved many of the error reporting sites.
Thanks for the quick response on this! I expect to spend some more time working with it this weekend
With pleasure! Thanks for spending time with MLStyle!
MLStyle
thinks this pattern is non-exhaustive:
julia> using MLStyle
julia> function canonicalize(expr :: Expr)
@match expr begin
:($x |> $f) => :($f($x))
Expr(:do, $g($x), $f) => :($g($f, $x))
x => x
end
end
ERROR: LoadError: InternalException("Non-exhaustive pattern found!")
Stacktrace:
[1] mk_gapp_pattern(::Symbol, ::Array{Any,1}, ::Expr, ::Array{Any,1}, ::Module) at /home/chad/.julia/packages/MLStyle/ksIXg/src/Pervasives.jl:502
[2] (::getfield(MLStyle.Infras, Symbol("##9#11")))(::Symbol, ::Expr, ::Module) at /home/chad/.julia/packages/MLStyle/ksIXg/src/Infras.jl:127
[3] mk_pattern(::Symbol, ::Expr, ::Module) at /home/chad/.julia/packages/MLStyle/ksIXg/src/MatchCore.jl:277
[4] (::getfield(MLStyle.Pervasives, Symbol("##135#142")){Symbol,Array{Any,1},Module,Symbol,Symbol,Symbol})(::Expr) at /home/chad/.julia/packages/MLStyle/ksIXg/src/Pervasives.jl:386
[5] foreach(::getfield(MLStyle.Pervasives, Symbol("##135#142")){Symbol,Array{Any,1},Module,Symbol,Symbol,Symbol}, ::Array{Any,1}) at ./abstractarray.jl:1866
[6] ordered_seq_match(::Symbol, ::Array{Any,1}, ::Module) at /home/chad/.julia/packages/MLStyle/ksIXg/src/Pervasives.jl:361
[7] (::getfield(MLStyle.Pervasives, Symbol("##101#106")))(::Symbol, ::Type, ::Array{Any,1}, ::Module) at /home/chad/.julia/packages/MLStyle/ksIXg/src/Pervasives.jl:275
[8] mk_app_pattern(::Symbol, ::Symbol, ::Array{Any,1}, ::Module) at /home/chad/.julia/packages/MLStyle/ksIXg/src/Infras.jl:93
[9] (::getfield(MLStyle.Infras, Symbol("##9#11")))(::Symbol, ::Expr, ::Module) at /home/chad/.julia/packages/MLStyle/ksIXg/src/Infras.jl:127
[10] mk_pattern(::Symbol, ::Expr, ::Module) at /home/chad/.julia/packages/MLStyle/ksIXg/src/MatchCore.jl:277
[11] (::getfield(MLStyle.MatchCore, Symbol("##51#53")){Symbol,Symbol,Module})(::Tuple{LineNumberNode,Expr,Expr}, ::Expr) at /home/chad/.julia/packages/MLStyle/ksIXg/src/MatchCore.jl:252
[12] mapfoldr_impl(::typeof(identity), ::getfield(MLStyle.MatchCore, Symbol("##51#53")){Symbol,Symbol,Module}, ::NamedTuple{(:init,),Tuple{Expr}}, ::Array{Any,1}, ::Int64) at ./reduce.jl:105
[13] #mapfoldr#189(::Base.Iterators.Pairs{Symbol,Expr,Tuple{Symbol},NamedTuple{(:init,),Tuple{Expr}}}, ::Function, ::Function, ::Function, ::Array{Any,1}) at ./reduce.jl:125
[14] #mapfoldr at ./none:0 [inlined]
[15] #foldr#190 at ./reduce.jl:144 [inlined]
[16] (::getfield(Base, Symbol("#kw##foldr")))(::NamedTuple{(:init,),Tuple{Expr}}, ::typeof(foldr), ::Function, ::Array{Any,1}) at ./none:0
[17] (::getfield(MLStyle.MatchCore, Symbol("##50#52")){Symbol,Symbol,Module})(::LineNumberNode) at /home/chad/.julia/packages/MLStyle/ksIXg/src/MatchCore.jl:250
[18] (::getfield(MLStyle.Toolz, Symbol("##1#2")){getfield(MLStyle.MatchCore, Symbol("##50#52")){Symbol,Symbol,Module}})(::MLStyle.MatchCore.config) at /home/chad/.julia/packages/MLStyle/ksIXg/src/Internal/Toolz.jl:25
[19] $(::getfield(MLStyle.Toolz, Symbol("##1#2")){getfield(MLStyle.MatchCore, Symbol("##50#52")){Symbol,Symbol,Module}}, ::MLStyle.MatchCore.config) at /home/chad/.julia/packages/MLStyle/ksIXg/src/Internal/Toolz.jl:8
[20] (::getfield(MLStyle.Toolz, Symbol("##1#2")){getfield(MLStyle.MatchCore, Symbol("##48#49")){Symbol,Module}})(::MLStyle.MatchCore.config) at /home/chad/.julia/packages/MLStyle/ksIXg/src/Internal/Toolz.jl:25
[21] $(::getfield(MLStyle.Toolz, Symbol("##1#2")){getfield(MLStyle.MatchCore, Symbol("##48#49")){Symbol,Module}}, ::MLStyle.MatchCore.config) at /home/chad/.julia/packages/MLStyle/ksIXg/src/Internal/Toolz.jl:8
[22] gen_match(::Symbol, ::Expr, ::Module) at /home/chad/.julia/packages/MLStyle/ksIXg/src/MatchCore.jl:220
[23] @match(::LineNumberNode, ::Module, ::Any, ::Any) at /home/chad/.julia/packages/MLStyle/ksIXg/src/MatchCore.jl:238
in expression starting at REPL[58]:3
Oops I got it, should have been
function canonicalize(expr :: Expr)
@match expr begin
:($x |> $f) => :($f($x))
Expr(:do, :($g($x)), :($f)) => :($g($f, $x))
x => x
end
end
So the above error should really be "$ outside expression" or something
Oh, thanks for this feedback, and we're to solve it sooner!
Actually there's a possibility that users have defined their own $
patterns outside expressions, although it must be rare and not recommended. Also, as there is no $
pattern in MLStyle's built-in patterns, I think the error message should be something like "No pattern $g. Are you using $ outside expression unexpectedly?"
Oh, it's positioned as a bug now, I'll get it done at once. But the last release might not come out very recently.
@cscherrer Hi Chad, now the error message becomes
LoadError: "Deconstructor cannot be an expression like \$(Expr(:\$, :g))."
with corresponding position info.
It could be explained with that $g(...)
is not a deconstructor.
The current problem is that string(Expr(:$, :g))
is "\$(Expr(:\$, :g))"
instead of "$g"
, so it still gets a bit confusing.
Hi Chad, is ERROR: LoadError: Deconstructor cannot be an expression like $(Expr(:$, :g)).
okay?
Planning to release v0.3.1 for introducing some new features during my recent talk.
Below might be a common problem with people new to pattern matching (or rusty with it like me, apparently). It would be really nice to have a clear error message that the problem here is with a non-exhaustive pattern match :)