Comments (12)
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.
from mlstyle.jl.
Would you like to try the master branch out? I've improved many of the error reporting sites.
from mlstyle.jl.
Thanks for the quick response on this! I expect to spend some more time working with it this weekend
from mlstyle.jl.
With pleasure! Thanks for spending time with MLStyle!
from mlstyle.jl.
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
from mlstyle.jl.
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
from mlstyle.jl.
Oh, thanks for this feedback, and we're to solve it sooner!
from mlstyle.jl.
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?"
from mlstyle.jl.
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.
from mlstyle.jl.
@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.
from mlstyle.jl.
Hi Chad, is ERROR: LoadError: Deconstructor cannot be an expression like $(Expr(:$, :g)).
okay?
from mlstyle.jl.
Planning to release v0.3.1 for introducing some new features during my recent talk.
from mlstyle.jl.
Related Issues (20)
- & might be a bad choice for de-interpolation HOT 7
- Capture dictionary keys and values. HOT 1
- @matchast does not produce informative error message HOT 2
- Unable to document `@data`
- How do you match on Pair? HOT 1
- Pattern "equality is strict for primitive types"
- `Vector{Int}` value fails to match `Vector{Any}` pattern
- Document `pattern_unmacrocall` usage
- Use doctests
- Expand docs for `pattern_uncall`
- Expand docs for `pattern_unref`
- Expand docs for `is_enum` and `enum_matcher`
- Explain active patterns
- Give a useful example of `let` patterns HOT 1
- Document GADTs HOT 1
- Show multiple `@case` expressions in the `@switch` docs
- Better error message for calling `@match` on non-record struct instance
- Automatic `@as_record` pattern matching HOT 1
- `@trymatch` to return `Some`
- Work with EnumX and other namespaced properties HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mlstyle.jl.