File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -2843,6 +2843,35 @@ expanded into a list of its elements:
2843
2843
of '0'..'9': echo "a number"
2844
2844
else: echo "other"
2845
2845
2846
+ The ``case `` statement doesn't produce an l-value, so the following example
2847
+ won't work:
2848
+
2849
+ .. code-block :: nim
2850
+ type
2851
+ Foo = ref object
2852
+ x: seq[string]
2853
+
2854
+ proc get_x(x: Foo): var seq[string] =
2855
+ # doesn't work
2856
+ case true
2857
+ of true:
2858
+ x.x
2859
+ else:
2860
+ x.x
2861
+
2862
+ var foo = Foo(x: @[])
2863
+ foo.get_x().add("asd")
2864
+
2865
+ This can be fixed by explicitly using ``return ``:
2866
+
2867
+ .. code-block :: nim
2868
+ proc get_x(x: Foo): var seq[string] =
2869
+ case true
2870
+ of true:
2871
+ return x.x
2872
+ else:
2873
+ return x.x
2874
+
2846
2875
2847
2876
When statement
2848
2877
--------------
You can’t perform that action at this time.
0 commit comments