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
This commit is contained in:
Jason Beetham 2021-10-26 03:29:07 -06:00 • committed by GitHub
commit 8d5a275189
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 56 additions and 3 deletions

View file

@ -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