fixes #5285
This commit is contained in:
parent
95d8558f0c
commit
abaf5d0bdb
5 changed files with 42 additions and 6 deletions
|
|
@ -1541,7 +1541,8 @@ proc skipGenericOwner*(s: PSym): PSym =
|
||||||
## Generic instantiations are owned by their originating generic
|
## Generic instantiations are owned by their originating generic
|
||||||
## symbol. This proc skips such owners and goes straight to the owner
|
## symbol. This proc skips such owners and goes straight to the owner
|
||||||
## of the generic itself (the module or the enclosing proc).
|
## of the generic itself (the module or the enclosing proc).
|
||||||
result = if s.kind in skProcKinds and sfFromGeneric in s.flags:
|
result = if s.kind in skProcKinds and {sfGenSym, sfFromGeneric} * s.flags ==
|
||||||
|
{sfFromGeneric}:
|
||||||
s.owner.owner
|
s.owner.owner
|
||||||
else:
|
else:
|
||||||
s.owner
|
s.owner
|
||||||
|
|
|
||||||
|
|
@ -97,10 +97,17 @@ proc genericCacheGet(genericSym: PSym, entry: TInstantiation;
|
||||||
if inst.compilesId == id and sameInstantiation(entry, inst[]):
|
if inst.compilesId == id and sameInstantiation(entry, inst[]):
|
||||||
return inst.sym
|
return inst.sym
|
||||||
|
|
||||||
|
when false:
|
||||||
|
proc `$`(x: PSym): string =
|
||||||
|
result = x.name.s & " " & " id " & $x.id
|
||||||
|
|
||||||
proc freshGenSyms(n: PNode, owner, orig: PSym, symMap: var TIdTable) =
|
proc freshGenSyms(n: PNode, owner, orig: PSym, symMap: var TIdTable) =
|
||||||
# we need to create a fresh set of gensym'ed symbols:
|
# we need to create a fresh set of gensym'ed symbols:
|
||||||
if n.kind == nkSym and sfGenSym in n.sym.flags and
|
#if n.kind == nkSym and sfGenSym in n.sym.flags:
|
||||||
(n.sym.owner == orig or n.sym.owner.kind == skPackage):
|
# if n.sym.owner != orig:
|
||||||
|
# echo "symbol ", n.sym.name.s, " orig ", orig, " owner ", n.sym.owner
|
||||||
|
if n.kind == nkSym and {sfGenSym, sfFromGeneric} * n.sym.flags == {sfGenSym}: # and
|
||||||
|
# (n.sym.owner == orig or n.sym.owner.kind in {skPackage}):
|
||||||
let s = n.sym
|
let s = n.sym
|
||||||
var x = PSym(idTableGet(symMap, s))
|
var x = PSym(idTableGet(symMap, s))
|
||||||
if x == nil:
|
if x == nil:
|
||||||
|
|
|
||||||
|
|
@ -112,6 +112,7 @@ type
|
||||||
toBind, toMixin, toInject: IntSet
|
toBind, toMixin, toInject: IntSet
|
||||||
owner: PSym
|
owner: PSym
|
||||||
cursorInBody: bool # only for nimsuggest
|
cursorInBody: bool # only for nimsuggest
|
||||||
|
scopeN: int
|
||||||
bracketExpr: PNode
|
bracketExpr: PNode
|
||||||
|
|
||||||
template withBracketExpr(ctx, x, body: untyped) =
|
template withBracketExpr(ctx, x, body: untyped) =
|
||||||
|
|
@ -141,8 +142,13 @@ proc isTemplParam(c: TemplCtx, n: PNode): bool {.inline.} =
|
||||||
|
|
||||||
proc semTemplBody(c: var TemplCtx, n: PNode): PNode
|
proc semTemplBody(c: var TemplCtx, n: PNode): PNode
|
||||||
|
|
||||||
proc openScope(c: var TemplCtx) = openScope(c.c)
|
proc openScope(c: var TemplCtx) =
|
||||||
proc closeScope(c: var TemplCtx) = closeScope(c.c)
|
openScope(c.c)
|
||||||
|
inc c.scopeN
|
||||||
|
|
||||||
|
proc closeScope(c: var TemplCtx) =
|
||||||
|
dec c.scopeN
|
||||||
|
closeScope(c.c)
|
||||||
|
|
||||||
proc semTemplBodyScope(c: var TemplCtx, n: PNode): PNode =
|
proc semTemplBodyScope(c: var TemplCtx, n: PNode): PNode =
|
||||||
openScope(c)
|
openScope(c)
|
||||||
|
|
@ -166,6 +172,7 @@ proc newGenSym(kind: TSymKind, n: PNode, c: var TemplCtx): PSym =
|
||||||
result = newSym(kind, considerQuotedIdent(n), c.owner, n.info)
|
result = newSym(kind, considerQuotedIdent(n), c.owner, n.info)
|
||||||
incl(result.flags, sfGenSym)
|
incl(result.flags, sfGenSym)
|
||||||
incl(result.flags, sfShadowed)
|
incl(result.flags, sfShadowed)
|
||||||
|
if c.scopeN == 0: incl(result.flags, sfFromGeneric)
|
||||||
|
|
||||||
proc addLocalDecl(c: var TemplCtx, n: var PNode, k: TSymKind) =
|
proc addLocalDecl(c: var TemplCtx, n: var PNode, k: TSymKind) =
|
||||||
# locals default to 'gensym':
|
# locals default to 'gensym':
|
||||||
|
|
|
||||||
21
tests/template/tgensymregression.nim
Normal file
21
tests/template/tgensymregression.nim
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
|
||||||
|
template mathPerComponent(op: untyped): untyped =
|
||||||
|
proc op*[N,T](v,u: array[N,T]): array[N,T] {.inline.} =
|
||||||
|
for i in 0 ..< len(result):
|
||||||
|
result[i] = `*`(v[i], u[i])
|
||||||
|
|
||||||
|
mathPerComponent(`***`)
|
||||||
|
# bug #5285
|
||||||
|
when true:
|
||||||
|
if isMainModule:
|
||||||
|
var v1: array[3, float64]
|
||||||
|
var v2: array[3, float64]
|
||||||
|
echo repr(v1 *** v2)
|
||||||
|
|
||||||
|
|
||||||
|
proc foo(): void =
|
||||||
|
var v1: array[4, float64]
|
||||||
|
var v2: array[4, float64]
|
||||||
|
echo repr(v1 *** v2)
|
||||||
|
|
||||||
|
foo()
|
||||||
|
|
@ -6,7 +6,7 @@ discard """
|
||||||
|
|
||||||
var i {.compileTime.} = 2
|
var i {.compileTime.} = 2
|
||||||
|
|
||||||
template defineId*(t: typedesc): stmt =
|
template defineId*(t: typedesc) =
|
||||||
const id {.genSym.} = i
|
const id {.genSym.} = i
|
||||||
static: inc(i)
|
static: inc(i)
|
||||||
proc idFor*(T: typedesc[t]): int {.inline, raises: [].} = id
|
proc idFor*(T: typedesc[t]): int {.inline, raises: [].} = id
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue