From ca25a2184e0c54e7bfa95326c691e1ff1caddc42 Mon Sep 17 00:00:00 2001 From: metagn <10591326+metagn@users.noreply.github.com> Date: Thu, 27 Apr 2023 16:41:59 +0300 Subject: [PATCH] always force open generic dot field symbols? fixes #21724 but might break code --- compiler/semgnrc.nim | 9 +++++---- tests/generics/tbaddeprecated.nim | 29 +++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 tests/generics/tbaddeprecated.nim diff --git a/compiler/semgnrc.nim b/compiler/semgnrc.nim index 7241a470205ae..101f984c7bc07 100644 --- a/compiler/semgnrc.nim +++ b/compiler/semgnrc.nim @@ -66,7 +66,7 @@ proc semGenericStmtSymbol(c: PContext, n: PNode, s: PSym, # Introduced in this pass! Leave it as an identifier. result = n of skProc, skFunc, skMethod, skIterator, skConverter, skModule: - result = symChoice(c, n, s, scOpen) + result = symChoice(c, n, s, if fromDotExpr: scForceOpen else: scOpen) of skTemplate, skMacro: # alias syntax, see semSym for skTemplate, skMacro if sfNoalias notin s.flags and not fromDotExpr: @@ -79,7 +79,7 @@ proc semGenericStmtSymbol(c: PContext, n: PNode, s: PSym, result = semGenericStmt(c, result, {}, ctx) discard c.friendModules.pop() else: - result = symChoice(c, n, s, scOpen) + result = symChoice(c, n, s, if fromDotExpr: scForceOpen else: scOpen) of skGenericParam: if s.typ != nil and s.typ.kind == tyStatic: if s.typ.n != nil: @@ -100,7 +100,7 @@ proc semGenericStmtSymbol(c: PContext, n: PNode, s: PSym, result = n onUse(n.info, s) of skEnumField: - result = symChoice(c, n, s, scOpen) + result = symChoice(c, n, s, if fromDotExpr: scForceOpen else: scOpen) else: result = newSymNode(s, n.info) onUse(n.info, s) @@ -159,7 +159,8 @@ proc fuzzyLookup(c: PContext, n: PNode, flags: TSemGenericFlags, let syms = semGenericStmtSymbol(c, n, s, ctx, flags, fromDotExpr=true) if syms.kind == nkSym: let choice = symChoice(c, n, s, scForceOpen) - choice.transitionSonsKind(nkClosedSymChoice) + # don't close, we don't know if it's an object field yet: + #choice.transitionSonsKind(nkClosedSymChoice) result = newDot(result, choice) else: result = newDot(result, syms) diff --git a/tests/generics/tbaddeprecated.nim b/tests/generics/tbaddeprecated.nim new file mode 100644 index 0000000000000..0b16edff71022 --- /dev/null +++ b/tests/generics/tbaddeprecated.nim @@ -0,0 +1,29 @@ +discard """ + output: ''' +not deprecated +not error +''' +""" + +# issue #21724 + +block: # deprecated + {.push warningAsError[Deprecated]: on.} + type + SomeObj = object + hey: bool + proc hey() {.deprecated: "Shouldn't use this".} = echo "hey" + proc gen(o: auto) = + if o.hey: + echo "not deprecated" + gen(SomeObj(hey: true)) + {.pop.} +block: # error + type + SomeObj = object + hey: bool + proc hey() {.error: "Shouldn't use this".} = echo "hey" + proc gen(o: auto) = + if o.hey: + echo "not error" + gen(SomeObj(hey: true))