diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2017-03-24 07:35:12 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-24 07:35:12 +0100 |
commit | 0d8a503e450b1d240fb5ab914f40aa30d7b6cd8b (patch) | |
tree | f66694969fbab1f4004e32c711346757c4ec608d | |
parent | 268a1f7cfd9d99ed0bcd2b19f47c35eb7c979e2a (diff) | |
download | Nim-0d8a503e450b1d240fb5ab914f40aa30d7b6cd8b.tar.gz |
fixes #5597; wrong eager template instantiation in generic context (#5601)
-rw-r--r-- | compiler/semgnrc.nim | 6 | ||||
-rw-r--r-- | tests/generics/t1050.nim | 13 |
2 files changed, 16 insertions, 3 deletions
diff --git a/compiler/semgnrc.nim b/compiler/semgnrc.nim index 47a094f9d..3938259ad 100644 --- a/compiler/semgnrc.nim +++ b/compiler/semgnrc.nim @@ -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 diff --git a/tests/generics/t1050.nim b/tests/generics/t1050.nim index a6f9a2482..9e83b5ff0 100644 --- a/tests/generics/t1050.nim +++ b/tests/generics/t1050.nim @@ -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 |