mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-05 04:27:44 +00:00
documented overload disambiguation [backport] (#18865)
* documented overload disambiguation [backport] * Update doc/manual.rst Co-authored-by: konsumlamm <44230978+konsumlamm@users.noreply.github.com> * documented overload disambiguation [backport] * documented overload disambiguation [backport] Co-authored-by: konsumlamm <44230978+konsumlamm@users.noreply.github.com>
This commit is contained in:
@@ -2708,6 +2708,24 @@ a parameter typed as `untyped` (for unresolved expressions) or the type class
|
||||
assert toSeq2(items(@[1,2])) == @[1, 2] # but items(@[1,2]) is
|
||||
|
||||
|
||||
Overload disambiguation
|
||||
=======================
|
||||
|
||||
For routine calls "overload resolution" is performed. There is a weaker form of
|
||||
overload resolution called *overload disambiguation* that is performed when an
|
||||
overloaded symbol is used in a context where there is additional type information
|
||||
available. Let `p` be an overloaded symbol. These contexts are:
|
||||
|
||||
- In a function call `q(..., p, ...)` when the corresponding formal parameter
|
||||
of `q` is a `proc` type. If `q` itself is overloaded then the cartesian product
|
||||
of every interpretation of `q` and `p` must be considered.
|
||||
- In an object constructor `Obj(..., field: p, ...)` when `field` is a `proc`
|
||||
type. Analogous rules exist for array/set/tuple constructors.
|
||||
- In a declaration like `x: T = p` when `T` is a `proc` type.
|
||||
|
||||
As usual, ambiguous matches produce a compile-time error.
|
||||
|
||||
|
||||
Statements and expressions
|
||||
==========================
|
||||
|
||||
@@ -4414,7 +4432,7 @@ would. For example:
|
||||
if n > 0:
|
||||
yield n
|
||||
for e in toItr(recCountDown(n - 1)):
|
||||
yield e
|
||||
yield e
|
||||
|
||||
for i in toItr(recCountDown(6)): # Emits: 6 5 4 3 2 1
|
||||
echo i
|
||||
|
||||
Reference in New Issue
Block a user