Might anyone be able to explain what's going on here?
julia> r = Ref{TypeVar(:I, Union{}, Integer)}
Ref{I<:Integer}
julia> tt(::Type{A}) where {A} = A
tt (generic function with 1 method)
julia> tt(r)
ERROR: UndefVarError: `A` not defined
Stacktrace:
[1] tt(#unused#::Type{Ref{I<:Integer}})
@ Main ./REPL[219]:1
[2] top-level scope
@ REPL[220]:1
Interesting one - I don't think you should be able to define r
like that
julia> r = Ref{I<:Integer}
ERROR: UndefVarError: `I` not defined
Stacktrace:
[1] top-level scope
@ REPL[1]:1
compared to
julia> r = Ref{I} where I <: Integer
Ref{I} where I<:Integer
julia> tt(::Type{A}) where {A} = A
tt (generic function with 1 method)
julia> tt(r)
Ref{I} where I<:Integer
since TypeVar
is mutable, it should not be possible to place it in that position - looks like a bug to me
I find this curious on two levels:
it's not a type that should be constructible, so it's unsurprising that the method says "this doesn't exist, what are you doooing"
would be good to have an issue for this, I think
I feel like it's more of a "is malformed" than "doesn't exist" situation
mutable objects are forbidden from being a type paremeter - the type quite literally does not (or isn't supposed to) exist/be constructible
I'm still surprised about TypeVar
being mutable
my guess is that this is so because it has to interface with C and writing that mutating then was/is easier in the compiler
Can you open an issue for this? Since this shouldn't be constructible, this ought to error I think
Done: https://github.com/JuliaLang/julia/issues/49799
Last updated: Nov 22 2024 at 04:41 UTC