How to check for unwanted specialization and how to prevent specialization?

Replacing _ with x avoided specialization for me (and only @nospecialize was required) Seems like a bug?

julia> f(@nospecialize _) = 7
f (generic function with 1 method)

julia> Base.specializations(@which f(1))
Base.MethodSpecializations(MethodInstance for f(::Int64))

julia> h(@nospecialize x) = 7
h (generic function with 1 method)

julia> Base.specializations(@which h(1))
Base.MethodSpecializations(MethodInstance for h(::Any))
3 Likes