Skip to content

Commit

Permalink
hygienic macrocall match & relax dict pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
thautwarm committed Mar 13, 2021
1 parent f541b6f commit 059dd34
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/MatchImpl.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function pattern_unref end
function pattern_unmacrocall(macro_func, self::Function, args::AbstractArray)
@sswitch args begin
@case [ln, m::Module, args...]
return self(macro_func(ln, m, args...))
return self(macroexpand(m, Expr(:macrocall, macro_func, ln, args...)))
end
end

Expand Down
8 changes: 4 additions & 4 deletions src/Pervasives.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ function MLStyle.pattern_uncall(
targs::AbstractArray,
args::AbstractArray,
)
isempty(tparams) || error("A (:) pattern requires no type params.")
isempty(targs) || error("A (:) pattern requires no type arguments.")

isempty(tparams) || return begin
call = Expr(:call, t, args...)
ann = Expr(:curly, t, targs...)
call = Expr(:call, Dict, args...)
ann = Expr(:curly, Dict, targs...)
self(Where(call, ann, tparams))
end

pairs = Pair[]
for arg in args
@switch arg begin
Expand Down
23 changes: 20 additions & 3 deletions test/issues/109.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
@test 20 == @match raw"123" begin
r"\Gaaa$" => 10
raw"123" => 20
@testcase "#109: matching macrocall" begin
@test 20 == @match raw"123" begin
r"\Gaaa$" => 10
raw"123" => 20
end

@lift @as_record struct Name
n
end

@lift macro some_macro()
n = esc(:Name)
:(Name($n))
end

f(Name) = @match Name begin
@some_macro() => Name
end

@test f(Name(1)) == 1
end
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ MODULE = TestModule

@use GADT

include("issues/109.jl")
include("when.jl")
include("untyped_lam.jl")
include("active_patterns.jl")
Expand All @@ -78,6 +79,5 @@ include("MQuery/test.jl")

include("issues/87.jl")
include("issues/62.jl")
include("issues/109.jl")

end

0 comments on commit 059dd34

Please sign in to comment.