Aqua.jl
Aqua.jl copied to clipboard
Test unbound arguments false positive in presence of vararg and typeassert
module MMM
f(xs::Vector{T}...) where {T<:Integer} = [one(T)*x for x in xs] # raises an error
g(x::Vector{T}) where {T<:Integer} = one(T)*x
h(xs...)= [one(eltype(x))*x for x in xs]
i(x) = one(eltype(x))*x
end
using Aqua
Aqua.test_unbound_args(MMM)
raises an error:
Test Failed at /home/stefan/.julia/packages/Aqua/HWLbM/src/unbound_args.jl:10
Expression: detect_unbound_args_recursively(m) == []
Evaluated: Any[f(xs::Vector{T}...) where T<:Integer @ Main.MMM scratch.jl:4] == Any[]
ERROR: There was an error during testing
julia> versioninfo()
Julia Version 1.9.0-DEV.1566
Commit ea991745a99 (2022-10-10 13:10 UTC)
Platform Info:
OS: Linux (x86_64-linux-gnu)
CPU: 16 × AMD Ryzen 7 1700 Eight-Core Processor
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-14.0.6 (ORCJIT, znver1)
Threads: 1 on 16 virtual cores
Environment:
JULIA_EDITOR = code
JULIA_NUM_THREADS = 1
pkg> st Aqua
Status `Project.toml`
[4c88cf16] Aqua v0.5.5
This is not a false positive:
julia> f(xs::Vector{T}...) where {T<:Integer} = [one(T)*x for x in xs]
f (generic function with 1 method)
julia> f()
ERROR: UndefVarError: T not defined
When xs is Vararg, this includes zero args. With zero args, T is unbound
Oh... thank you!
I will not close this issue myself in case the maintainers deem a special error message explaining this is warranted. Of course, it is perfectly reasonable for the maintainers to simply close the issue too.
Is there a way to solve unbound cases which involve N unspecified as in Array{T<:Real, N}?
This kind of changes the subject since this is not a false positive. But it would be nice to have a more informative error message. Or better and easier perhaps a link to a page explaining typical causes of the error
It might take a while to understand that instead of this
struct MyStruct{IntT<:Integer}
v::Tuple{Vararg{IntT}}
end
you really wanted this
struct MyStruct{IntT<:Integer}
v::Tuple{IntT, Vararg{IntT}}
end
I was using this in conjunction with a macro in Parameters.jl, so the line identifying the error was in Parameters.jl. I assumed it had something to do with the macro rewriting my struct. Of course this was not the case.