summary refs log tree commit diff stats
path: root/doc
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2022-10-21 06:55:52 +0200
committerGitHub <noreply@github.com>2022-10-21 06:55:52 +0200
commit76763f51aa119e71b00200142292acf5f1fdc69c (patch)
treec30b7c3c685d32cfa2c2dd79757e57204a85ab0c /doc
parent4aa67ad7fd3179bd46fbeb793c3c71d14d9021a0 (diff)
downloadNim-76763f51aa119e71b00200142292acf5f1fdc69c.tar.gz
implemented strictCaseObjects (#20608)
* implemented strictCaseObjects

* changelog update
Diffstat (limited to 'doc')
-rw-r--r--doc/manual_experimental.md36
1 files changed, 36 insertions, 0 deletions
diff --git a/doc/manual_experimental.md b/doc/manual_experimental.md
index 59d6a407b..748637478 100644
--- a/doc/manual_experimental.md
+++ b/doc/manual_experimental.md
@@ -1941,3 +1941,39 @@ constructors that take inheritance into account.
 
 **Note**: The implementation of "strict definitions" and "out parameters" is experimental but the concept
 is solid and it is expected that eventually this mode becomes the default in later versions.
+
+
+Strict case objects
+===================
+
+With `experimental: "strictCaseObjects"` *every* field access is checked to be valid at compile-time.
+The field is within a `case` section of an `object`.
+
+  ```nim
+  {.experimental: "strictCaseObjects".}
+
+  type
+    Foo = object
+      case b: bool
+      of false:
+        s: string
+      of true:
+        x: int
+
+  var x = Foo(b: true, x: 4)
+  case x.b
+  of true:
+    echo x.x # valid
+  of false:
+    echo "no"
+
+  case x.b
+  of false:
+    echo x.x # error: field access outside of valid case branch: x.x
+  of true:
+    echo "no"
+
+  ```
+
+**Note**: The implementation of "strict case objects" is experimental but the concept
+is solid and it is expected that eventually this mode becomes the default in later versions.