Fix semantic pass with borrowed magic procs (#8945)

Reported by pqflx3 on the forum.
This commit is contained in:
LemonBoy 2018-09-11 20:32:25 +02:00 • committed by Andreas Rumpf
commit 8670f4911b
2 changed files with 11 additions and 0 deletions

View file

@ -1173,6 +1173,9 @@ proc semBorrow(c: PContext, n: PNode, s: PSym) =
if b != nil:
# store the alias:
n.sons[bodyPos] = newSymNode(b)
# Carry over the original symbol magic, this is necessary in order to ensure
# the semantic pass is correct
s.magic = b.magic
else:
localError(c.config, n.info, errNoSymbolToBorrowFromFound)

View file

@ -0,0 +1,8 @@
type
Bytes = distinct seq[byte]
proc add(x: var Bytes; b: byte) {.borrow.}
var x = @[].Bytes
x.add(42)
let base = cast[seq[byte]](x)
doAssert base.len == 1 and base[0] == 42