Description
It is possible to define methods where Julia is unable to determine a concrete value for a type parameter, leading to a UndefVarError
:
julia> foo(::Ref{<:T}) where T = T
foo (generic function with 1 method)
julia> foo(Ref{String}())
String
julia> foo(Ref{AbstractString}())
ERROR: UndefVarError: `T` not defined
The error is confusing since, from a user's perspective, T
is very much defined/declared in the where
part of the method definition.
Rather, could we throw a dedicated AmbiguousTypeParameter
error here (bikeshed, please)? Preferably with a docstring that would explain that it's possible to construct signatures where you can't uniquely figure out a type. And would also probably suggest avoiding unnecessary subtyping in method signature (like in the Ref{<:T}
example above), since that is most likely an error on the user's part.
A couple of related issues I was able to find: #25307, #39277, #39280, #41841, #41728. It also caused some discussion on Zulip recently.
While for a different issue, the hints in #34393 might also help with the implementation here.