@@ -386,38 +386,39 @@ arguments:
386
386
julia> g(x::Float64, y) = 2x + y;
387
387
388
388
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.
396
389
397
390
julia> g(2.0, 3)
398
391
7.0
399
392
400
393
julia> g(2, 3.0)
401
394
8.0
402
395
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
407
397
``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:
412
400
413
401
.. doctest ::
414
402
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 ::
416
415
417
416
julia> g(x::Float64, y) = 2x + y;
418
417
419
418
julia> g(x, y::Float64) = x + 2y;
420
419
420
+ julia> g(x::Float64, y::Float64) = 2x + 2y;
421
+
421
422
julia> g(2.0, 3)
422
423
7.0
423
424
@@ -427,10 +428,6 @@ the intersection case:
427
428
julia> g(2.0, 3.0)
428
429
10.0
429
430
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
-
434
431
.. _man-parametric-methods :
435
432
436
433
Parametric Methods
0 commit comments