Unbound Type Parameters

An unbound type parameter is a type parameter with a where, that does not occur in the signature of some dispatch of the method.

Examples

The following methods each have T as an unbound type parameter:

julia> f(x::Int) where {T} = do_something(x)WARNING: method definition for f at REPL[1]:1 declares type variable T but does not use it.
f (generic function with 1 method)
julia> g(x::T...) where {T} = println(T)g (generic function with 1 method)

In the cases of f above, the unbound type parameter T is neither present in the signature of the methods nor as a bound of another type parameter. Here, the type parameter T can be removed without changing any semantics.

For signatures with Vararg (cf. g above), the type parameter is unbound for the zero-argument case (e.g. g()).

julia> g(1.0, 2.0)Float64
julia> g(1)Int64
julia> g()ERROR: UndefVarError: `T` not defined

A possible fix would be to replace g by two methods.

julia> g() = println(Int)  # Defaults to `Int`g (generic function with 1 method)
julia> g(x1::T, x2::T...) where {T} = println(T)g (generic function with 2 methods)
julia> g(1.0, 2.0)Float64
julia> g(1)Int64
julia> g()Int64

Test function

Aqua.test_unbound_argsFunction
test_unbound_args(module::Module)

Test that all methods in module and its submodules do not have unbound type parameters. An unbound type parameter is a type parameter with a where, that does not occur in the signature of some dispatch of the method.

Keyword Arguments

  • broken::Bool = false: If true, it uses @test_broken instead of @test.