Skip to content

Commit cb1d984

Browse files
committed
added test for type inference with multiple usage of setmacro within the same macro
1 parent eefb661 commit cb1d984

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

test/test_setmacro.jl

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,31 @@ using StaticNumbers
4646
@test m3 === @SMatrix[1 0; 0 0]
4747
end
4848

49+
function test_all_inferrable(f, argtypes)
50+
typed = first(code_typed(f, argtypes))
51+
code = typed.first
52+
@test all(T -> !(T isa UnionAll || T === Any), code.slottypes)
53+
end
54+
55+
# Example of macro that caused inference issues before.
56+
macro test_macro(expr)
57+
quote
58+
function f($(esc(:x)))
59+
$(Setfield.setmacro(identity, expr, overwrite=true))
60+
$(Setfield.setmacro(identity, expr, overwrite=true))
61+
$(Setfield.setmacro(identity, expr, overwrite=true))
62+
$(Setfield.setmacro(identity, expr, overwrite=true))
63+
$(Setfield.setmacro(identity, expr, overwrite=true))
64+
return $(esc(:x))
65+
end
66+
end
67+
end
68+
69+
@testset "setmacro multiple usage" begin
70+
let f = @test_macro(x[end] = 1)
71+
test_all_inferrable(f, (Vector{Float64}, ))
72+
end
73+
end
74+
4975
end#module
5076

0 commit comments

Comments
 (0)