fixes #12612 [backport] (#12681)

This commit is contained in:
Andreas Rumpf 2019-11-19 12:09:36 +01:00 • committed by GitHub
commit 56a00da34a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 6 deletions

View file

@ -220,9 +220,9 @@ proc getFreeRegister(cc: PCtx; k: TSlotKind; start: int): TRegister =
return TRegister(i)
if c.maxSlots >= high(TRegister):
globalError(cc.config, cc.bestEffort, "VM problem: too many registers required")
result = TRegister(c.maxSlots)
c.slots[c.maxSlots] = (inUse: true, kind: k)
inc c.maxSlots
result = TRegister(max(c.maxSlots, start))
c.slots[result] = (inUse: true, kind: k)
c.maxSlots = result + 1
proc getTemp(cc: PCtx; tt: PType): TRegister =
let typ = tt.skipTypesOrNil({tyStatic})
@ -1483,7 +1483,10 @@ proc checkCanEval(c: PCtx; n: PNode) =
if {sfCompileTime, sfGlobal} <= s.flags: return
if s.kind in {skVar, skTemp, skLet, skParam, skResult} and
not s.isOwnedBy(c.prc.sym) and s.owner != c.module and c.mode != emRepl:
cannotEval(c, n)
# little hack ahead for bug #12612: assume gensym'ed variables
# are in the right scope:
if sfGenSym in s.flags and c.prc.sym == nil: discard
else: cannotEval(c, n)
elif s.kind in {skProc, skFunc, skConverter, skMethod,
skIterator} and sfForward in s.flags:
cannotEval(c, n)

View file

@ -134,6 +134,14 @@ doAssert fmt"{nat:3o}" == "100"
doAssert fmt"{nat:3x}" == " 40"
doAssert fmt"{nat:3X}" == " 40"
# bug #12612
proc my_proc =
const value = "value"
const a = &"{value}"
assert a == value
my_proc()
block:
template fmt(pattern: string; openCloseChar: char): untyped =
fmt(pattern, openCloseChar, openCloseChar)