Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non-exhaustive pattern error when using multiple lambdas inside constructor/function call #190

Open
ReubenJ opened this issue Aug 9, 2024 · 1 comment

Comments

@ReubenJ
Copy link

ReubenJ commented Aug 9, 2024

Multiple calls to the inside a constructor or method call seem to produce an erroneous matching non-exhaustive error.

julia> struct SomeStruct
                   one_lambda
                   another_lambda
               end

julia> SomeStruct( begin
           _ => true
       end,  begin
           _ => true
       end)
ERROR: LoadError: matching non-exhaustive, at #= ~/.julia/packages/MLStyle/SLOsr/src/StandardPatterns/LambdaCases.jl:27 =#
Stacktrace:
 [1] error(s::String)
   @ Base ./error.jl:35
 [2] gen_lambda(cases::Any, source::LineNumberNode, mod::Module)
   @ MLStyle.LambdaCases ~/.julia/packages/MLStyle/SLOsr/src/StandardPatterns/LambdaCases.jl:49
 [3] var"@λ"(__source__::LineNumberNode, __module__::Module, cases::Any)
   @ MLStyle.LambdaCases ~/.julia/packages/MLStyle/SLOsr/src/StandardPatterns/LambdaCases.jl:78
in expression starting at REPL[5]:1

If I instead place the calls to the macro outside of the constructor, no matching error is produced.

julia> one_lambda =  begin
           _ => true
       end
##λ#226 (generic function with 1 method)

julia> another_lambda =  begin
           _ => true
       end
##λ#230 (generic function with 1 method)

julia> SomeStruct(one_lambda, another_lambda)
SomeStruct(var"##λ#226", var"##λ#230")

I would expect the behavior to be the same for both cases.

Interestingly, the error does not occur with a single call:

julia> struct SomeOtherStruct
          one_lambda
       end

julia> SomeOtherStruct( begin
           _ => true
       end)
SomeOtherStruct(var"##λ#234")
Manifest to reproduce

julia_version = "1.10.3"
manifest_format = "2.0"
project_hash = "06dc1a8f7f58f18641326ca54395a788118a84d3"

[[deps.MLStyle]]
git-tree-sha1 = "bc38dff0548128765760c79eb7388a4b37fae2c8"
uuid = "d8e11817-5142-5d16-987a-aa16d5891078"
version = "0.4.17"

@ReubenJ
Copy link
Author

ReubenJ commented Aug 9, 2024

This can be avoided by using parentheses:

SomeStruct(( begin
           _ => true
       end), ( begin
           _ => true
       end))

Without the parentheses, the first macro also consumes the call to the second one. I'm not familiar enough with building macros to say whether this is normal and/or avoidable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant