summary refs log tree commit diff stats
path: root/doc
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2019-06-27 21:21:55 +0200
committerAndreas Rumpf <rumpf_a@web.de>2019-06-27 21:25:07 +0200
commitd9604d7d0b4cffa2f446d09ab0923d61b124a2af (patch)
tree2492e5185a688ae308475ee8777490f71317973e /doc
parentf36a61e6d41603200ef1b39dcb503fd9b7d977bc (diff)
downloadNim-d9604d7d0b4cffa2f446d09ab0923d61b124a2af.tar.gz
manual: document how accessors are resolved; fixes #11514
Diffstat (limited to 'doc')
-rw-r--r--doc/manual.rst19
1 files changed, 19 insertions, 0 deletions
diff --git a/doc/manual.rst b/doc/manual.rst
index ac66c2550..3b8346ef1 100644
--- a/doc/manual.rst
+++ b/doc/manual.rst
@@ -3298,6 +3298,25 @@ different; for this a special setter syntax is needed:
   new s
   s.host = 34  # same as `host=`(s, 34)
 
+A proc defined as ``f=`` (with the trailing ``=``) is called
+a `setter`:idx:. A setter can be called explicitly via the common
+backticks notation:
+
+.. code-block:: nim
+
+  proc `f=`(x: MyObject; value: string) =
+    discard
+
+  `f=`(myObject, "value")
+
+
+``f=`` can called implicitly in the pattern
+``x.f = value`` if and only if the type of ``x`` does not have a field
+named ``f`` or if ``f`` is not visible in the current module. These rules
+ensure that object fields and accessors can have the same name. Within the
+module ``x.f`` is then always interpreted as field access and outside the
+module it is interpreted as an accessor proc call.
+
 
 Command invocation syntax
 -------------------------