nsajko
January 22, 2024, 6:45am
1
opened 12:18PM - 21 Jan 24 UTC
bug
types and dispatch
Perplexing bug on master (but not on v1.10). EDIT: but see below, the basic bug … existed already on v1.6
When I run this code in a fresh REPL session, all lines succeed:
```julia
f(::Type{<:Tuple{Vararg{A}}}) where {A} = A
f(Tuple{Vararg{Int}})
f(Tuple{Vararg{T}} where {T<:Int})
```
If the order of the calls to `f` is reversed, though, both calls error:
```julia-repl
julia> f(::Type{<:Tuple{Vararg{A}}}) where {A} = A
f (generic function with 1 method)
julia> f(Tuple{Vararg{T}} where {T<:Int})
ERROR: UndefVarError: `A` not defined in static parameter matching
Suggestion: run Test.detect_unbound_args to detect method arguments that do not fully constrain a type parameter.
Stacktrace:
[1] f(::Type{Tuple{Vararg{T}} where T<:Int64})
@ Main ./REPL[1]:1
[2] top-level scope
@ REPL[2]:1
julia> f(Tuple{Vararg{Int}})
ERROR: UndefVarError: `A` not defined in static parameter matching
Suggestion: run Test.detect_unbound_args to detect method arguments that do not fully constrain a type parameter.
Stacktrace:
[1] f(::Type{Tuple{Vararg{T}} where T<:Int64})
@ Main ./REPL[1]:1
[2] top-level scope
@ REPL[3]:1
```
Version info:
```
Julia Version 1.11.0-DEV.1347
Commit 1f111e1326a (2024-01-20 19:02 UTC)
Build Info:
Official https://julialang.org/ release
Platform Info:
OS: Linux (x86_64-linux-gnu)
CPU: 8 × AMD Ryzen 3 5300U with Radeon Graphics
WORD_SIZE: 64
LLVM: libLLVM-16.0.6 (ORCJIT, znver2)
Threads: 1 default, 0 interactive, 1 GC (on 8 virtual cores)
```
This script succeeds as expected (run as script or try in a fresh REPL session):
f(::Type{<:Tuple{Vararg{A}}}) where {A} = A
struct S end
f(Tuple{Vararg{S}})
f(Tuple{Vararg{T}} where {T<:S})
But if the order of the calls to f
is reversed, exchanging the last two lines, all calls of f
fail. With any Julia version I tried.
Can anyone think of a workaround? My perspective is that I want to write a function like f
that should work for all possible A
, not just for known types like S
.