This commit is contained in:
Andreas Rumpf
2017-02-04 21:00:07 +01:00
parent 95d8558f0c
commit abaf5d0bdb
5 changed files with 42 additions and 6 deletions

View File

@@ -1541,7 +1541,8 @@ proc skipGenericOwner*(s: PSym): PSym =
## Generic instantiations are owned by their originating generic
## symbol. This proc skips such owners and goes straight to the owner
## 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
else:
s.owner

View File

@@ -97,10 +97,17 @@ proc genericCacheGet(genericSym: PSym, entry: TInstantiation;
if inst.compilesId == id and sameInstantiation(entry, inst[]):
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) =
# we need to create a fresh set of gensym'ed symbols:
if n.kind == nkSym and sfGenSym in n.sym.flags and
(n.sym.owner == orig or n.sym.owner.kind == skPackage):
#if n.kind == nkSym and sfGenSym in n.sym.flags:
# 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
var x = PSym(idTableGet(symMap, s))
if x == nil:

View File

@@ -112,6 +112,7 @@ type
toBind, toMixin, toInject: IntSet
owner: PSym
cursorInBody: bool # only for nimsuggest
scopeN: int
bracketExpr: PNode
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 openScope(c: var TemplCtx) = openScope(c.c)
proc closeScope(c: var TemplCtx) = closeScope(c.c)
proc openScope(c: var TemplCtx) =
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 =
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)
incl(result.flags, sfGenSym)
incl(result.flags, sfShadowed)
if c.scopeN == 0: incl(result.flags, sfFromGeneric)
proc addLocalDecl(c: var TemplCtx, n: var PNode, k: TSymKind) =
# locals default to 'gensym':

View 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()

View File

@@ -6,7 +6,7 @@ discard """
var i {.compileTime.} = 2
template defineId*(t: typedesc): stmt =
template defineId*(t: typedesc) =
const id {.genSym.} = i
static: inc(i)
proc idFor*(T: typedesc[t]): int {.inline, raises: [].} = id