From 7874c0efcb2437c378c973a51de88f3ebc7e4d74 Mon Sep 17 00:00:00 2001 From: Araq Date: Wed, 26 Mar 2014 08:42:27 +0100 Subject: [PATCH] borrow dots for distinct types documented --- doc/manual.txt | 22 ++++++++++++++++++++++ tests/distinct/tborrowdot.nim | 13 +++++++++++++ todo.txt | 1 - 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 tests/distinct/tborrowdot.nim diff --git a/doc/manual.txt b/doc/manual.txt index c2acd3e6a8..6526ba2cb8 100644 --- a/doc/manual.txt +++ b/doc/manual.txt @@ -1569,6 +1569,28 @@ currency. This can be solved with templates_. defineCurrency(TEuro, int) +The borrow pragma can also be used to annotate the distinct type to allow +certain builtin operations to be lifted: + +.. code-block:: nimrod + type + Foo = object + a, b: int + s: string + + Bar {.borrow: `.`.} = distinct Foo + + var bb: ref Bar + new bb + # field access now valid + bb.a = 90 + bb.s = "abc" + +Currently only the dot accessor can be borrowed in this way. + + + + Void type --------- diff --git a/tests/distinct/tborrowdot.nim b/tests/distinct/tborrowdot.nim new file mode 100644 index 0000000000..820ee3b718 --- /dev/null +++ b/tests/distinct/tborrowdot.nim @@ -0,0 +1,13 @@ + +type + Foo = object + a, b: int + s: string + + Bar {.borrow: `.`.} = distinct Foo + +var bb: ref Bar +new bb +bb.a = 90 +bb.s = "abc" + diff --git a/todo.txt b/todo.txt index 91fa0cd6a6..7a315545ee 100644 --- a/todo.txt +++ b/todo.txt @@ -4,7 +4,6 @@ version 0.9.4 - fix gensym capture bug - fix GC issues - Bugs ====