fixes #5597; wrong eager template instantiation in generic context (#5601)

This commit is contained in:
Andreas Rumpf 2017-03-24 07:35:12 +01:00 • committed by GitHub
commit 0d8a503e45
2 changed files with 16 additions and 3 deletions

View file

@ -51,10 +51,10 @@ template macroToExpand(s): untyped =
s.kind in {skMacro, skTemplate} and (s.typ.len == 1 or sfAllUntyped in s.flags) s.kind in {skMacro, skTemplate} and (s.typ.len == 1 or sfAllUntyped in s.flags)
template macroToExpandSym(s): untyped = template macroToExpandSym(s): untyped =
s.kind in {skMacro, skTemplate} and (s.typ.len == 1) s.kind in {skMacro, skTemplate} and (s.typ.len == 1) and not fromDotExpr
proc semGenericStmtSymbol(c: PContext, n: PNode, s: PSym, proc semGenericStmtSymbol(c: PContext, n: PNode, s: PSym,
ctx: var GenericCtx): PNode = ctx: var GenericCtx; fromDotExpr=false): PNode =
semIdeForTemplateOrGenericCheck(n, ctx.cursorInBody) semIdeForTemplateOrGenericCheck(n, ctx.cursorInBody)
incl(s.flags, sfUsed) incl(s.flags, sfUsed)
case s.kind case s.kind
@ -145,7 +145,7 @@ proc fuzzyLookup(c: PContext, n: PNode, flags: TSemGenericFlags,
elif s.name.id in ctx.toMixin: elif s.name.id in ctx.toMixin:
result = newDot(result, symChoice(c, n, s, scForceOpen)) result = newDot(result, symChoice(c, n, s, scForceOpen))
else: else:
let syms = semGenericStmtSymbol(c, n, s, ctx) let syms = semGenericStmtSymbol(c, n, s, ctx, fromDotExpr=true)
if syms.kind == nkSym: if syms.kind == nkSym:
let choice = symChoice(c, n, s, scForceOpen) let choice = symChoice(c, n, s, scForceOpen)
choice.kind = nkClosedSymChoice choice.kind = nkClosedSymChoice

View file

@ -14,3 +14,16 @@ proc arrayItem(a: ArrayType): auto =
var arr: ArrayType[int] var arr: ArrayType[int]
echo arrayItem(arr) echo arrayItem(arr)
# bug #5597
template fail() = "what"
proc g[T](x: var T) =
x.fail = 3
type
Obj = object
fail: int
var y: Obj
g y