Skip to content

Commit 059dd34

Browse files
committed
hygienic macrocall match & relax dict pattern
1 parent f541b6f commit 059dd34

File tree

4 files changed

+26
-9
lines changed

4 files changed

+26
-9
lines changed

src/MatchImpl.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function pattern_unref end
1818
function pattern_unmacrocall(macro_func, self::Function, args::AbstractArray)
1919
@sswitch args begin
2020
@case [ln, m::Module, args...]
21-
return self(macro_func(ln, m, args...))
21+
return self(macroexpand(m, Expr(:macrocall, macro_func, ln, args...)))
2222
end
2323
end
2424

src/Pervasives.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ function MLStyle.pattern_uncall(
3131
targs::AbstractArray,
3232
args::AbstractArray,
3333
)
34-
isempty(tparams) || error("A (:) pattern requires no type params.")
35-
isempty(targs) || error("A (:) pattern requires no type arguments.")
34+
3635
isempty(tparams) || return begin
37-
call = Expr(:call, t, args...)
38-
ann = Expr(:curly, t, targs...)
36+
call = Expr(:call, Dict, args...)
37+
ann = Expr(:curly, Dict, targs...)
3938
self(Where(call, ann, tparams))
4039
end
40+
4141
pairs = Pair[]
4242
for arg in args
4343
@switch arg begin

test/issues/109.jl

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,21 @@
1-
@test 20 == @match raw"123" begin
2-
r"\Gaaa$" => 10
3-
raw"123" => 20
1+
@testcase "#109: matching macrocall" begin
2+
@test 20 == @match raw"123" begin
3+
r"\Gaaa$" => 10
4+
raw"123" => 20
5+
end
6+
7+
@lift @as_record struct Name
8+
n
9+
end
10+
11+
@lift macro some_macro()
12+
n = esc(:Name)
13+
:(Name($n))
14+
end
15+
16+
f(Name) = @match Name begin
17+
@some_macro() => Name
18+
end
19+
20+
@test f(Name(1)) == 1
421
end

test/runtests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ MODULE = TestModule
5252

5353
@use GADT
5454

55+
include("issues/109.jl")
5556
include("when.jl")
5657
include("untyped_lam.jl")
5758
include("active_patterns.jl")
@@ -78,6 +79,5 @@ include("MQuery/test.jl")
7879

7980
include("issues/87.jl")
8081
include("issues/62.jl")
81-
include("issues/109.jl")
8282

8383
end

0 commit comments

Comments
 (0)