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:
parent
6cd219c3a3
commit
ca51bb8fd9
1 changed files with 19 additions and 1 deletions
|
|
@ -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
|
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
|
Statements and expressions
|
||||||
==========================
|
==========================
|
||||||
|
|
||||||
|
|
@ -4414,7 +4432,7 @@ would. For example:
|
||||||
if n > 0:
|
if n > 0:
|
||||||
yield n
|
yield n
|
||||||
for e in toItr(recCountDown(n - 1)):
|
for e in toItr(recCountDown(n - 1)):
|
||||||
yield e
|
yield e
|
||||||
|
|
||||||
for i in toItr(recCountDown(6)): # Emits: 6 5 4 3 2 1
|
for i in toItr(recCountDown(6)): # Emits: 6 5 4 3 2 1
|
||||||
echo i
|
echo i
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue