Skip to content

errorshow: Hint on same-named types from different modules#61648

Open
adienes wants to merge 9 commits intoJuliaLang:masterfrom
adienes:dispatch-shadow-errmsg
Open

errorshow: Hint on same-named types from different modules#61648
adienes wants to merge 9 commits intoJuliaLang:masterfrom
adienes:dispatch-shadow-errmsg

Conversation

@adienes
Copy link
Copy Markdown
Member

@adienes adienes commented Apr 24, 2026

when you have types of the same name but different modules, and accidentally pass the wrong one to a function, the MethodError can be confusing until you realize what happened. this attempts to add a hint to alleviate that.

example:

julia> module Geometry
           struct Point
               x::Float64
               y::Float64
           end
           translate(p::Point, dx, dy) = Point(p.x + dx, p.y + dy)
       end
Main.Geometry

julia> struct Point
           lat::Float64
           lon::Float64
       end

julia> p = Point(40.7, -74.0);

julia> Geometry.translate(p, 1, 2)

# BEFORE
ERROR: MethodError: no method matching translate(::Point, ::Int64, ::Int64)
The function `translate` exists, but no method is defined for this combination of argument types.

Closest candidates are:
  translate(::Main.Geometry.Point, ::Any, ::Any)
   @ Main.Geometry REPL[3]:6


# AFTER
ERROR: MethodError: no method matching translate(::Point, ::Int64, ::Int64)
You may have intended `Main.Geometry.Point` rather than `Main.Point`.
The function `translate` exists, but no method is defined for this combination of argument types.

Closest candidates are:
  translate(::Main.Geometry.Point, ::Any, ::Any)
   @ Main.Geometry REPL[4]:6

fixes #41084
half claude half me

When a MethodError occurs because an argument's type is shadowed by a
same-named type from another module that the method actually expects,
print an explicit hint naming both types with their module prefixes.
Without this, both types print as a bare `Foo` and the divergence is
easy to miss.

This pull request was written with the assistance of generative AI
(Claude Opus 4.7).

Fixes JuliaLang#41084

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@adienes adienes marked this pull request as draft April 24, 2026 19:58
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@adienes adienes closed this Apr 24, 2026
@adienes adienes reopened this Apr 25, 2026
@adienes adienes added the error messages Better, more actionable error messages label Apr 25, 2026
@adienes adienes marked this pull request as ready for review April 25, 2026 14:24
Comment thread base/errorshow.jl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

error messages Better, more actionable error messages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve error message when dispatch doesn't work when type is overshadowed by a type of the same name

2 participants