document 'var T' and 'typedesc' restriction in generics; closes #1156

This commit is contained in:
Araq
2018-09-03 11:38:15 +02:00
parent 47cbe0e54d
commit 4993274f2f

View File

@@ -4387,6 +4387,34 @@ be inferred to have the equivalent of the `any` type class and thus they will
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
--------