nsajko
April 2, 2023, 10:08pm
1
A module:
module M
f(::Tuple{}) = nothing
f(::NTuple{n, F}) where {n, F} = F
end
The second method gets flagged as having an unbound argument, even though the first method protects it from ever being called in such a situation:
julia> detect_unbound_args(M)
[1] f(::Tuple{Vararg{F, n}}) where {n, F} in Main.M at REPL[2]:3
Should this be considered a bug? If not, detect_unbound_args
seems useless, as this seems like a very basic false positive. Hope I’m not misunderstanding Julia 101 or something.
This happens with both Julia nightly and with 1.8.5.
Elrod
April 3, 2023, 2:50am
2
It’s definitely annoying. I don’t even know how to call the second method with an empty tuple using invoke
.
If you want to avoid it, instead write
f(::Tuple{F,Vararg{F,nMinus1}}) where {F,nMinus1} = ...
I do this. detect_unbound_args
is useful, but less so now that you get warnings during precompilation.
4 Likes
nsajko
April 3, 2023, 3:28am
3
Wow, I’ll definitely keep this “tuple type with minimal size” trick in mind.
Yeah its an issue,
opened 01:44PM - 09 Sep 22 UTC
bug
duplicate
test: unbound args
Let's say that I have a module
```julia
module abcd
f(::NTuple{N, T}) where… {N,T} = (N,T)
f(::Tuple{}) = (0,Any)
end # module
```
Testing this using Aqua, I obtain
```julia
Unbound type parameters: Test Failed at /home/jishnu/.julia/packages/Aqua/HWLbM/src/unbound_args.jl:10
Expression: detect_unbound_args_recursively(m) == []
Evaluated: Any[f(::Tuple{Vararg{T, N}}) where {N, T} in abcd at /home/jishnu/Dropbox/JuliaPackages/abcd/src/abcd.jl:3] == Any[]
Stacktrace:
[1] macro expansion
@ ~/packages/julias/julia-1.8/share/julia/stdlib/v1.8/Test/src/Test.jl:464 [inlined]
[2] test_unbound_args(m::Module)
@ Aqua ~/.julia/packages/Aqua/HWLbM/src/unbound_args.jl:10
```
The issue seems to be with the `T` argument, and I think it's because in the `N=0` case, `T` becomes an unbound argument in the first method. However, this method is not called in the `N=0` case because the second method is more specific. Perhaps this should be ignored from the report?
The function calls are:
```julia
julia> abcd.f(())
(0, Any)
julia> abcd.f((1,))
(1, Int64)
```
If I'm missing something here, could someone please clarify this?
opened 06:31PM - 12 Jul 18 UTC
domain:types and dispatch
testsystem
EDIT: it's not entirely obvious this is a bug. Below the key comparison is reduc… ed to
```julia
foo1(::Type{Tuple{R1,Vararg{R1,N}}}) where {N,T1,R1<:AbstractUnitRange{T1}}
```
vs
```julia
foo2(::Type{NTuple{N,R1}}) where {N,T1,R1<:AbstractUnitRange{T1}}
```
I think that what this really comes down to is
```julia
julia> Tuple{} <: NTuple{0, T} where T<:AbstractUnitRange
true
```
#### original post
```julia
julia> using Test
julia> foo(::Type{NTuple{N,R1}}, ::Type{NTuple{N,R2}}) where {N,R1<:AbstractUnitRange{T1},R2<:AbstractUnitRange{T2}} where {T1,T2} =
NTuple{N,promote_type(R1,R2)}
foo (generic function with 1 method)
julia> m = first(Base.MethodList(typeof(foo).name.mt))
foo(::Type{Tuple{Vararg{R1,N}}}, ::Type{Tuple{Vararg{R2,N}}}) where {T1, T2, N, R1<:AbstractUnitRange{T1}, R2<:AbstractUnitRange{T2}} in Main at REPL[2]:1
julia> Test.has_unbound_vars(m.sig)
true
```
I *think* it's fair to say that method definition does not have unbound typevars. I am guessing this is a consequence of [the loop](https://github.com/JuliaLang/julia/blob/b0f531e5f0b626f1ee91bb7cac2a0bb660f435f3/stdlib/Test/src/Test.jl#L1468-L1477) dropping old typevars.
its been there for a long time someone should fix it :3