Aqua: "Unbound type parameters detected" for parametric structures

Aqua.jl complains about the following code for the structure StructBad
with the error Unbound type parameters detected. Is this a real problem in the code or a false positive of Aqua? The structures StructOK2 and StructOK3 are fine.

using Aqua
module mymod

struct StructBad{N,TC}
    field::NTuple{N,TC}
end

struct StructOK2{TC}
    field::NTuple{2,TC}
end

struct StructOK3{N}
    field::NTuple{N,Int}
end

end

Aqua.test_unbound_args(mymod)

The full error message is:

Unbound type parameters detected:
[1] Main.mymod.StructBad(field::Tuple{Vararg{TC, N}}) where {N, TC} @ Main.mymod ~/.julia/dev/CommonDataModel/test/test_aqua2.jl:5                                        
Test Failed at /home/abarth/.julia/packages/Aqua/tHrmY/src/unbound_args.jl:37
  Expression: isempty(unbounds)
   Evaluated: isempty(Method[Main.mymod.StructBad(field::Tuple{Vararg{TC, N}}) where {N, TC} @ Main.mymod ~/.julia/dev/CommonDataModel/test/test_aqua2.jl:5])

ERROR: LoadError: There was an error during testing
in expression starting at /home/abarth/.julia/dev/CommonDataModel/test/test_aqua2.jl:18

(v1.10) pkg> st Aqua
Status `/mnt/data1/abarth/.julia/environments/v1.10/Project.toml`
  [4c88cf16] Aqua v0.8.7

(v1.10) pkg> 

The problem is that calling StructBad(()) (the 0-length tuple as input), only fixes N=0, but the type parameter TC cannot be deduced by the input. Calling the above indeed errors in the REPL.

3 Likes

Thanks a lot! I use now the following definition which does not have this problem:

struct Struct{TC<:NTuple}
    field::TC
end

This seems to work as well (I’m not sure if the use of Union{} here is really correct, but a zero-length NTuple can’t be inhabited, so I went with that instead of Any).

julia> struct StructOkN{N,TC}
           field::NTuple{N,TC}
       end

julia> StructOkN(::Tuple{}) = StructOkN{0,Union{}}(())
StructOkN

julia> StructOkN((1,2,3))
StructOkN{3, Int64}((1, 2, 3))

julia> StructOkN(())
StructOkN{0, Union{}}(())
1 Like

Interesting! Thank you!

1 Like