Skip to content

don't warn/error symbols in semGenericStmt/templates #24907

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Apr 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions compiler/semexprs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ proc semExprNoDeref(c: PContext, n: PNode, flags: TExprFlags = {}): PNode =

proc semSymGenericInstantiation(c: PContext, n: PNode, s: PSym): PNode =
result = symChoice(c, n, s, scClosed)
if result.kind == nkSym:
markUsed(c, n.info, s)

proc semSym(c: PContext, n: PNode, sym: PSym, flags: TExprFlags): PNode

Expand Down Expand Up @@ -3288,6 +3290,7 @@ proc semExpr(c: PContext, n: PNode, flags: TExprFlags = {}, expectedType: PType
#performProcvarCheck(c, n, s)
result = symChoice(c, n, s, scClosed)
if result.kind == nkSym:
markUsed(c, n.info, s)
markIndirect(c, result.sym)
# if isGenericRoutine(result.sym):
# localError(c.config, n.info, errInstantiateXExplicitly, s.name.s)
Expand Down
3 changes: 2 additions & 1 deletion compiler/semgnrc.nim
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,8 @@ proc semGenericStmt(c: PContext, n: PNode,
result = lookup(c, n, flags, ctx)
if result != nil and result.kind == nkSym:
assert result.sym != nil
markUsed(c, n.info, result.sym)
incl result.sym.flags, sfUsed
markOwnerModuleAsUsed(c, result.sym)
of nkDotExpr:
#let luf = if withinMixin notin flags: {checkUndeclared} else: {}
#var s = qualifiedLookUp(c, n, luf)
Expand Down
9 changes: 3 additions & 6 deletions compiler/semtempl.nim
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,9 @@ proc symChoice(c: PContext, n: PNode, s: PSym, r: TSymChoiceRule;
# for instance 'nextTry' is both in tables.nim and astalgo.nim ...
if not isField or sfGenSym notin s.flags:
result = newSymNode(s, info)
if isField:
# possibly not final field sym
incl(s.flags, sfUsed)
markOwnerModuleAsUsed(c, s)
else:
markUsed(c, info, s)
# possibly not final field sym
incl(s.flags, sfUsed)
markOwnerModuleAsUsed(c, s)
onUse(info, s)
else:
result = n
Expand Down
3 changes: 0 additions & 3 deletions nimsuggest/tests/tqualified_highlight.nim
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ discard """
$nimsuggest --tester $file
>highlight $1
highlight;;skProc;;1;;7;;4
highlight;;skProc;;1;;7;;4
highlight;;skTemplate;;2;;7;;4
highlight;;skTemplate;;2;;7;;4
highlight;;skTemplate;;2;;7;;4
highlight;;skFunc;;3;;8;;1
"""
39 changes: 39 additions & 0 deletions tests/generics/toptions.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
discard """
matrix: "--warningAsError:Deprecated"
"""

block: # bug #24905
proc y() {.deprecated.} = discard
proc v(_: int | int) =
{.push warning[Deprecated]: off.}
y()
{.pop.}

v(1)

block: # bug #24903
block:
proc y() {.deprecated.} = discard
proc m(_: int | int) =
when false: y()

block:
proc y() {.error.} = discard
proc m(_: int | int) =
when false: y()

block:
proc y() {.error.} = discard
proc m(_: int | int) =
when true: y()

block: # bug #15650
proc bar() {.deprecated.} = discard

template foo() =
when false:
bar()
else:
discard

foo()