# MethodErrors suggest fixes that may depend on internal bindings

**URL:** <https://discourse.julialang.org/t/methoderrors-suggest-fixes-that-may-depend-on-internal-bindings/106468>\
**Category:** Internals & Design\
**Tags:** namespaces\
**Created:** [November 20, 2023, 2:47pm UTC](https://discourse.julialang.org/t/methoderrors-suggest-fixes-that-may-depend-on-internal-bindings/106468 "2023-11-20T14:47:24Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jishnub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jishnub/32/33620_2.png) [@jishnub](https://discourse.julialang.org/u/jishnub)\
**Post date:** [November 20, 2023, 2:47pm UTC](https://discourse.julialang.org/t/methoderrors-suggest-fixes-that-may-depend-on-internal-bindings/106468/1 "2023-11-20T14:47:24Z")

</div>

On Julia v1.11:

```julia
julia> using FillArrays, LinearAlgebra

julia> Zeros(2,2) * UpperTriangular(Zeros(2,2))
ERROR: MethodError: *(::Zeros{Float64, 2, Tuple{Base.OneTo{Int64}, Base.OneTo{Int64}}}, ::UpperTriangular{Float64, Zeros{Float64, 2, Tuple{Base.OneTo{Int64}, Base.OneTo{Int64}}}}) is ambiguous.

Candidates:
  *(a::FillArrays.AbstractZeros{T, 2} where T, b::AbstractMatrix)
    @ FillArrays ~/.julia/packages/FillArrays/p9YG6/src/fillalgebra.jl:89
  *(A::AbstractMatrix, B::LinearAlgebra.AbstractTriangular)
    @ LinearAlgebra ~/packages/julias/julia-latest/share/julia/stdlib/v1.11/LinearAlgebra/src/triangular.jl:1501

Possible fix, define
  *(::FillArrays.AbstractZeros{T, 2} where T, ::LinearAlgebra.AbstractTriangular)

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

```

The suggestion is to define a method that dispatches on `LinearAlgebra.AbstractTriangular`. If I check what that is, I obtain

```julia
help?> LinearAlgebra.AbstractTriangular
  │ Warning
  │
  │ The following bindings may be internal; they may change or be removed in future versions:
  │
  │ • LinearAlgebra.AbstractTriangular

  No documentation found for private symbol.

```

This doesn’t inspire much confidence in the proposed fix. I’m unsure what’s the best solution is in general, but in this specific example, the resolution might be to define methods for `UpperTriangular` and `LowerTriangular` separately.

---

<div class="post-metadata">

**Author:** ![BioTurboNick](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bioturbonick/32/6380_2.png) [@BioTurboNick](https://discourse.julialang.org/u/BioTurboNick)\
**Post date:** [November 20, 2023, 4:06pm UTC](https://discourse.julialang.org/t/methoderrors-suggest-fixes-that-may-depend-on-internal-bindings/106468/2 "2023-11-20T16:06:15Z")

</div>

I’d say the issue is that types used in a public API call should also be public.

---

<div class="post-metadata">

**Author:** ![CameronBieganek](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cameronbieganek/32/6915_2.png) [@CameronBieganek](https://discourse.julialang.org/u/CameronBieganek)\
**Post date:** [November 21, 2023, 3:51am UTC](https://discourse.julialang.org/t/methoderrors-suggest-fixes-that-may-depend-on-internal-bindings/106468/3 "2023-11-21T03:51:47Z")

</div>

Oh boy. I have a feeling these new “Possible fix” messages are going to inspire a lot of type piracy among inexperienced users.

---

<div class="post-metadata">

**Author:** ![fatteneder](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fatteneder/32/33991_2.png) [@fatteneder](https://discourse.julialang.org/u/fatteneder)\
**Post date:** [November 21, 2023, 2:27pm UTC](https://discourse.julialang.org/t/methoderrors-suggest-fixes-that-may-depend-on-internal-bindings/106468/4 "2023-11-21T14:27:12Z")

</div>

These messages are not new, they were already present on `v1.3` and perhaps even earlier.

For completeness: the above can be easily generated with a MWE like this:

```julia-repl
julia> abstract type Super end

julia> struct A <: Super end

julia> struct B <: Super end

julia> foo(a::A, b::Super) = 1
foo (generic function with 1 method)

julia> foo(a::Super, b::B) = 2
foo (generic function with 2 methods)

julia> foo(A(), B())
ERROR: MethodError: foo(::A, ::B) is ambiguous.

Candidates:
  foo(a::A, b::Super)
    @ Main REPL[4]:1
  foo(a::Super, b::B)
    @ Main REPL[5]:1

Possible fix, define
  foo(::A, ::B)

Stacktrace:
 [1] top-level scope

```

---

<div class="post-metadata">

**Author:** ![jishnub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jishnub/32/33620_2.png) [@jishnub](https://discourse.julialang.org/u/jishnub)\
**Post date:** [November 21, 2023, 3:06pm UTC](https://discourse.julialang.org/t/methoderrors-suggest-fixes-that-may-depend-on-internal-bindings/106468/5 "2023-11-21T15:06:47Z")

</div>

> [@fatteneder](#):
>
> These messages are not new

Yeah, I meant the warning about the symbols not being public is new, whereas the situation was more nebulous earlier. They were never public, but there was no explicit warning that these may be removed.

I guess the solution is to nudge packages to not use private types in dispatch for user-facing methods, as suggested above. This may be done through Aqua checks.

---

<div class="post-metadata">

**Author:** ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)\
**Post date:** [November 21, 2023, 6:35pm UTC](https://discourse.julialang.org/t/methoderrors-suggest-fixes-that-may-depend-on-internal-bindings/106468/6 "2023-11-21T18:35:21Z")

</div>

I _think_ an ambiguity error would only ever suggest an internal/private binding if the package _is already_ using that internal/private binding.
