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
parent 268a1f7cfd
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)
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,
ctx: var GenericCtx): PNode =
ctx: var GenericCtx; fromDotExpr=false): PNode =
semIdeForTemplateOrGenericCheck(n, ctx.cursorInBody)
incl(s.flags, sfUsed)
case s.kind
@@ -145,7 +145,7 @@ proc fuzzyLookup(c: PContext, n: PNode, flags: TSemGenericFlags,
elif s.name.id in ctx.toMixin:
result = newDot(result, symChoice(c, n, s, scForceOpen))
else:
let syms = semGenericStmtSymbol(c, n, s, ctx)
let syms = semGenericStmtSymbol(c, n, s, ctx, fromDotExpr=true)
if syms.kind == nkSym:
let choice = symChoice(c, n, s, scForceOpen)
choice.kind = nkClosedSymChoice

View File

@@ -14,3 +14,16 @@ proc arrayItem(a: ArrayType): auto =
var arr: ArrayType[int]
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