diff --git a/Project.toml b/Project.toml index c6aba78..96d1858 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "Tricks" uuid = "410a4b4d-49e4-4fbc-ab6d-cb71b17b3775" authors = ["Frames White"] -version = "0.1.8" +version = "0.1.9" [compat] julia = "1.0" diff --git a/src/Tricks.jl b/src/Tricks.jl index 2f7fff1..0cd8749 100644 --- a/src/Tricks.jl +++ b/src/Tricks.jl @@ -100,7 +100,7 @@ function _method_table_all_edges_all_methods(f, T, world = Base.get_world_counte # We add an edge to the MethodTable itself so that when any new methods # are defined, it recompiles the function. - mt_edges = Core.Compiler.vect(mt, Tuple{Vararg{Any}}) + mt_edges = Core.Compiler.vect(mt, Tuple{f,Vararg{Any}}) # We want to add an edge to _every existing method instance_, so that # the deletion of any one of them will trigger recompilation of the function. diff --git a/test/runtests.jl b/test/runtests.jl index faae174..3b1e384 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -206,6 +206,34 @@ VERSION >= v"1.3" && @testset "static_method_count" begin i(x) = x+1 @test static_method_count(i) == 1 end + + @testset "parametric struct" begin + struct Baz{T}; x::T end + @test static_method_count(Baz) == 1 + @test static_method_count(Baz{Int}) == 1 + @test static_method_count(Baz{Tuple}) == 1 + + + Baz(x::Int) = Baz(x) + @test static_method_count(Baz) == 2 + Baz{Float64}(x::Int, y::Int) = Baz(x/y) + @test static_method_count(Baz{Float64}) == 2 + + Base.delete_method((first ∘ methods)(Baz)) + @test static_method_count(Baz) == 1 + Base.delete_method((first ∘ methods)(Baz{Float64})) + @test static_method_count(Baz{Float64}) == 1 + + Base.delete_method((first ∘ methods)(Baz)) + @test static_method_count(Baz) == 0 + Base.delete_method((first ∘ methods)(Baz{Float64})) + @test static_method_count(Baz{Float64}) == 0 + + Baz(x::Int) = Baz(x) + @test static_method_count(Baz) == 1 + Baz{Float64}(x::Int, y::Int) = Baz(x/y) + @test static_method_count(Baz{Float64}) == 1 + end end VERSION >= v"1.3" && @testset "closures" begin