Skip to content

Commit bcbbc10

Browse files
committed
DOC: Fix the manual for method ambiguities
The way of handling method ambiguities changed in JuliaLang#16125. Now Julia throws an error when calling an ambiguous methods, instead of just giving a warning when it was defined. This updates the manual to reflect the change. Fixes JuliaLang#16630.
1 parent 85535ae commit bcbbc10

File tree

1 file changed

+17
-20
lines changed

1 file changed

+17
-20
lines changed

doc/manual/methods.rst

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -386,38 +386,39 @@ arguments:
386386
julia> g(x::Float64, y) = 2x + y;
387387

388388
julia> g(x, y::Float64) = x + 2y;
389-
WARNING: New definition
390-
g(Any, Float64) at none:1
391-
is ambiguous with:
392-
g(Float64, Any) at none:1.
393-
To fix, define
394-
g(Float64, Float64)
395-
before the new definition.
396389

397390
julia> g(2.0, 3)
398391
7.0
399392

400393
julia> g(2, 3.0)
401394
8.0
402395

403-
julia> g(2.0, 3.0)
404-
7.0
405-
406-
Here the call ``g(2.0, 3.0)`` could be handled by either the
396+
But the call ``g(2.0, 3.0)`` could be handled by either the
407397
``g(Float64, Any)`` or the ``g(Any, Float64)`` method, and neither is
408-
more specific than the other. In such cases, Julia warns you about this
409-
ambiguity, but allows you to proceed, arbitrarily picking a method. You
410-
should avoid method ambiguities by specifying an appropriate method for
411-
the intersection case:
398+
more specific than the other. In such cases, Julia throws an error,
399+
instead of arbitrarily picking a method:
412400

413401
.. doctest::
414402

415-
julia> g(x::Float64, y::Float64) = 2x + 2y;
403+
julia> g(2.0, 3.0)
404+
ERROR: MethodError: g(::Float64, ::Float64) is ambiguous. Candidates:
405+
g(x::Float64, y) at REPL[9]:1
406+
g(x, y::Float64) at REPL[8]:1
407+
in eval(::Module, ::Any) at ./boot.jl:234
408+
in macro expansion at ./REPL.jl:92 [inlined]
409+
in (::Base.REPL.##1#2{Base.REPL.REPLBackend})() at ./event.jl:46
410+
411+
You should avoid method ambiguities by specifying an appropriate method for
412+
the intersection case:
413+
414+
.. doctest::
416415

417416
julia> g(x::Float64, y) = 2x + y;
418417

419418
julia> g(x, y::Float64) = x + 2y;
420419

420+
julia> g(x::Float64, y::Float64) = 2x + 2y;
421+
421422
julia> g(2.0, 3)
422423
7.0
423424

@@ -427,10 +428,6 @@ the intersection case:
427428
julia> g(2.0, 3.0)
428429
10.0
429430

430-
To suppress Julia's warning, the disambiguating method must be defined
431-
first, since otherwise the ambiguity exists, if transiently, until the
432-
more specific method is defined.
433-
434431
.. _man-parametric-methods:
435432

436433
Parametric Methods

0 commit comments

Comments
 (0)