document 'var T' and 'typedesc' restriction in generics; closes #1156
This commit is contained in:
parent
47cbe0e54d
commit
4993274f2f
1 changed files with 28 additions and 0 deletions
|
|
@ -4387,6 +4387,34 @@ be inferred to have the equivalent of the `any` type class and thus they will
|
||||||
match anything without discrimination.
|
match anything without discrimination.
|
||||||
|
|
||||||
|
|
||||||
|
Generic inference restrictions
|
||||||
|
------------------------------
|
||||||
|
|
||||||
|
The types ``var T`` and ``typedesc[T]`` cannot be inferred in a generic
|
||||||
|
instantiation. The following is not allowed:
|
||||||
|
|
||||||
|
.. code-block:: nim
|
||||||
|
:test: "nim c $1"
|
||||||
|
:status: 1
|
||||||
|
|
||||||
|
proc g[T](f: proc(x: T); x: T) =
|
||||||
|
f(x)
|
||||||
|
|
||||||
|
proc c(y: int) = echo y
|
||||||
|
proc v(y: var int) =
|
||||||
|
y += 100
|
||||||
|
var i: int
|
||||||
|
|
||||||
|
# allowed: infers 'T' to be of type 'int'
|
||||||
|
g(c, 42)
|
||||||
|
|
||||||
|
# not valid: 'T' is not inferred to be of type 'var int'
|
||||||
|
g(v, i)
|
||||||
|
|
||||||
|
# also not allowed: explict instantiation via 'var int'
|
||||||
|
g[var int](v, i)
|
||||||
|
|
||||||
|
|
||||||
Concepts
|
Concepts
|
||||||
--------
|
--------
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue