Skip to content

Cthulhu should display ambiguous method matches #695

@Keno

Description

@Keno
julia> struct _CtorSlotNarrowVal end

julia> Base.convert(::Type{_CtorSlotNarrowVal}, ::Any) = _CtorSlotNarrowVal()

julia> mutable struct _CtorSlotNarrowHolder
           x::_CtorSlotNarrowVal
       end

julia> Base.infer_effects(convert, Tuple{Type{_CtorSlotNarrowHolder}, Any})
(+c,+e,!n,+t,+s,+m,+u,+o,+r)

I was investigating where that nothrow taint was coming from. Turns out:

julia> Base.methods_including_ambiguous(convert, Tuple{Type{_CtorSlotNarrowVal}, Any})
# 2 methods for generic function "convert" from Base:
 [1] convert(::Type{T}, x::T) where T
     @ Base_compiler.jl:133
 [2] convert(::Type{_CtorSlotNarrowVal}, ::Any)
     @ REPL[9]:1

julia> convert(_CtorSlotNarrowVal, _CtorSlotNarrowVal())
ERROR: MethodError: convert(::Type{_CtorSlotNarrowVal}, ::_CtorSlotNarrowVal) is ambiguous.

Candidates:
  convert(::Type{_CtorSlotNarrowVal}, ::Any)
    @ Main REPL[16]:1
  convert(::Type{T}, x::T) where T
    @ Base Base_compiler.jl:133

Possible fix, define
  convert(::Type{_CtorSlotNarrowVal}, ::_CtorSlotNarrowVal)

Stacktrace:
 [1] top-level scope
   @ REPL[19]:1

So it's smarter than me, but I feel like this should have been annotated in the callsite display.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions