parent
2a4aa24620
commit
038f47e7b9
1 changed files with 29 additions and 0 deletions
|
|
@ -2843,6 +2843,35 @@ expanded into a list of its elements:
|
||||||
of '0'..'9': echo "a number"
|
of '0'..'9': echo "a number"
|
||||||
else: echo "other"
|
else: echo "other"
|
||||||
|
|
||||||
|
The ``case`` statement doesn't produce an l-value, so the following example
|
||||||
|
won't work:
|
||||||
|
|
||||||
|
.. code-block:: nim
|
||||||
|
type
|
||||||
|
Foo = ref object
|
||||||
|
x: seq[string]
|
||||||
|
|
||||||
|
proc get_x(x: Foo): var seq[string] =
|
||||||
|
# doesn't work
|
||||||
|
case true
|
||||||
|
of true:
|
||||||
|
x.x
|
||||||
|
else:
|
||||||
|
x.x
|
||||||
|
|
||||||
|
var foo = Foo(x: @[])
|
||||||
|
foo.get_x().add("asd")
|
||||||
|
|
||||||
|
This can be fixed by explicitly using ``return``:
|
||||||
|
|
||||||
|
.. code-block:: nim
|
||||||
|
proc get_x(x: Foo): var seq[string] =
|
||||||
|
case true
|
||||||
|
of true:
|
||||||
|
return x.x
|
||||||
|
else:
|
||||||
|
return x.x
|
||||||
|
|
||||||
|
|
||||||
When statement
|
When statement
|
||||||
--------------
|
--------------
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue