summary refs log tree commit diff stats
path: root/tests/borrow
diff options
context:
space:
mode:
authorJason Beetham <beefers331@gmail.com>2021-10-26 03:29:07 -0600
committerGitHub <noreply@github.com>2021-10-26 11:29:07 +0200
commit8d5a27518929bd4c54f4beb7e40a5fc382d3dd05 (patch)
tree2280f8122f8e5daad73e93e3faee1db865258bd5 /tests/borrow
parent83a2515af7aeb9a1c12015321243399a0d1f4c95 (diff)
downloadNim-8d5a27518929bd4c54f4beb7e40a5fc382d3dd05.tar.gz
Fixed distinct composite type class proc borrowing (#18904)
* Fixed composite type class proc borrowing

* Moved borrow search into transf

* added borrow check to symbol flag
Diffstat (limited to 'tests/borrow')
-rw-r--r--tests/borrow/typeclassborrow.nim32
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/borrow/typeclassborrow.nim b/tests/borrow/typeclassborrow.nim
new file mode 100644
index 000000000..62cb77d67
--- /dev/null
+++ b/tests/borrow/typeclassborrow.nim
@@ -0,0 +1,32 @@
+type
+  Foo = distinct seq[int]
+  Bar[N: static[int]] = distinct seq[int]
+  Baz = distinct Bar[10]
+
+proc newSeq(s: var Foo, n: Natural) {.borrow.}
+proc newSeq(s: var Bar, n: Natural) {.borrow.}
+proc newSeq(s: var Baz, n: Natural) {.borrow.}
+
+
+proc `$`(s: Foo): string {.borrow.}
+proc `$`(s: Bar): string {.borrow.}
+proc `$`(s: Baz): string {.borrow.}
+
+proc doThing(b: Bar) = discard
+proc doThing(b: Baz) {.borrow.}
+
+var
+  foo: Foo
+  bar: Bar[10]
+  baz: Baz
+
+newSeq(foo, 100)
+newSeq(bar, bar.N)
+newSeq(baz, 10)
+
+bar.doThing()
+baz.doThing()
+
+assert $seq[int](foo) == $foo
+assert $seq[int](bar) == $bar
+assert $seq[int](baz) == $baz
\ No newline at end of file