Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement ambiguity hint #71

Merged
merged 2 commits into from
Mar 2, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/ambiguities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,29 @@ function test_ambiguities_impl(
println("Ambiguity #", i)
println(m1)
println(m2)
ambiguity_hint(m1, m2)
println()
println()
end
return ambiguities == []
end

function ambiguity_hint(m1::Method, m2::Method)
# based on base/errorshow.jl#showerror_ambiguous
# https://github.com/JuliaLang/julia/blob/v1.7.2/base/errorshow.jl#L327-L353
sigfix = Any
sigfix = typeintersect(m1.sig, sigfix)
sigfix = typeintersect(m2.sig, sigfix)
if isa(Base.unwrap_unionall(sigfix), DataType) && sigfix <: Tuple
let sigfix = sigfix
if all(m->Base.morespecific(sigfix, m.sig), [m1, m2])
Copy link
Contributor

@giordano giordano Mar 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This broke Julia v1.0-1.3:

julia> Base.morespecific
ERROR: UndefVarError: morespecific not defined

print("\nPossible fix, define\n ")
Base.show_tuple_as_call(stdout, :function, sigfix)
else
println()
print("To resolve the ambiguity, try making one of the methods more specific, or ")
print("adding a new method more specific than any of the existing applicable methods.")
end
end
end
end