Fix semantic pass with borrowed magic procs (#8945)
Reported by pqflx3 on the forum.
This commit is contained in:
parent
e7d4043406
commit
8670f4911b
2 changed files with 11 additions and 0 deletions
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
8
tests/ccgbugs/tborrowmagic.nim
Normal file
8
tests/ccgbugs/tborrowmagic.nim
Normal 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue