Skip to content

Clearer error message when unable to determine exact type parameter value in a method #48731

Closed
@mortenpi

Description

@mortenpi

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    error messagesBetter, more actionable error messages

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions