Skip to content

Commit

Permalink
always force open generic dot field symbols?
Browse files Browse the repository at this point in the history
fixes nim-lang#21724 but might break code
  • Loading branch information
metagn committed Apr 27, 2023
1 parent 220b450 commit ca25a21
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
9 changes: 5 additions & 4 deletions compiler/semgnrc.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
29 changes: 29 additions & 0 deletions tests/generics/tbaddeprecated.nim
Original file line number Diff line number Diff line change
@@ -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))

0 comments on commit ca25a21

Please sign in to comment.