So, I just found out about Base.test.@inferred
and this looks like a nice way to ensure that functions are type-stable.
Is there any reason one shouldn’t use @inferred
by default in all package tests? (That is, can/should I replace all @test
statements with @test @inferred
?)
You donn’t use @test @inferred
, just @inferred
. If you want to make sure everything is inferred, you can, There are many things that aren’t inferrable though.
I do it in a lot of places and it usually looks something like this: https://github.com/JuliaML/LossFunctions.jl/blob/master/test/tst_api.jl#L30-L33. Works like a charm. Note that it seems using parenthesis are important when doing @test @inferred(...) == ...
.