diff --git a/compiler/semgnrc.nim b/compiler/semgnrc.nim index 47a094f9d7..3938259ad1 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 a6f9a2482d..9e83b5ff06 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