Skip to content

Unbound type param false positive in Type{Union{...}} #341

@nickrobinson251

Description

@nickrobinson251

Consider the module:

module Foo
    foo(::Type{Union{Nothing,Vector{T}}}) where T = 1
    foo(::Type{Nothing}) = 2
    foo(::Type{Vector{T}}) where T = 3
end

As far as I can tell, T cannot be unbound in the first definition, because it is only dispatched to by a Union{Nothing,Vector{T}} where T, e.g.

julia> begin
                  using .Foo: foo
                  @show foo(Vector{Int})
                  @show foo(Nothing)
                  @show foo(Union{Nothing,Vector{Float64}}) # only this call can hit the first definition
                  # no other calls would match the signature:
                  @show Type{Nothing} <: Type{Union{Nothing,Vector{T}}} where T
                  @show Type{Vector{Float64}} <: Type{Union{Nothing,Vector{T}}} where T
                  @show Type{Union{Nothing,Vector}} <: Type{Union{Nothing,Vector{T}}} where T
       end
foo(Vector{Int}) = 3
foo(Nothing) = 2
foo(Union{Nothing, Vector{Float64}}) = 1
Type{Nothing} <: (Type{Union{Nothing, Vector{T}}} where T) = false
Type{Vector{Float64}} <: (Type{Union{Nothing, Vector{T}}} where T) = false
Type{Union{Nothing, Vector}} <: (Type{Union{Nothing, Vector{T}}} where T) = false

But Aqua.test_unbound_args says T can be unbound:

julia> Aqua.test_unbound_args(Foo)
Unbound type parameters detected:
[1] foo(::Type{Union{Nothing, Vector{T}}}) where T @ Main.Foo REPL[12]:2
Test Failed at /Users/nickr/.julia/packages/Aqua/EPo21/src/unbound_args.jl:37
  Expression: isempty(unbounds)
   Evaluated: isempty(Method[foo(::Type{Union{Nothing, Vector{T}}}) where T @ Main.Foo REPL[12]:2])
ERROR: There was an error during testing

I think this is a false positive?

(Note this is not the same case as the Type issue in #333 or the Union 'issues' in #265 or #252)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions