Skip to content

Commit 0506d5b

Browse files
authored
don't warn/error symbols in semGenericStmt/templates (#24907)
fixes #24905 fixes #24903 fixes #11805 fixes #15650 In the first phase of generic checking, we cannot warn/error symbols because they can belong a false branch of `when` or there is a `push/pop` options using open symbols. So we cannot decide whether to warn/error or not
1 parent 8518cf0 commit 0506d5b

File tree

5 files changed

+47
-10
lines changed

5 files changed

+47
-10
lines changed

compiler/semexprs.nim

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ proc semExprNoDeref(c: PContext, n: PNode, flags: TExprFlags = {}): PNode =
113113

114114
proc semSymGenericInstantiation(c: PContext, n: PNode, s: PSym): PNode =
115115
result = symChoice(c, n, s, scClosed)
116+
if result.kind == nkSym:
117+
markUsed(c, n.info, s)
116118

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

@@ -3288,6 +3290,7 @@ proc semExpr(c: PContext, n: PNode, flags: TExprFlags = {}, expectedType: PType
32883290
#performProcvarCheck(c, n, s)
32893291
result = symChoice(c, n, s, scClosed)
32903292
if result.kind == nkSym:
3293+
markUsed(c, n.info, s)
32913294
markIndirect(c, result.sym)
32923295
# if isGenericRoutine(result.sym):
32933296
# localError(c.config, n.info, errInstantiateXExplicitly, s.name.s)

compiler/semgnrc.nim

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,8 @@ proc semGenericStmt(c: PContext, n: PNode,
274274
result = lookup(c, n, flags, ctx)
275275
if result != nil and result.kind == nkSym:
276276
assert result.sym != nil
277-
markUsed(c, n.info, result.sym)
277+
incl result.sym.flags, sfUsed
278+
markOwnerModuleAsUsed(c, result.sym)
278279
of nkDotExpr:
279280
#let luf = if withinMixin notin flags: {checkUndeclared} else: {}
280281
#var s = qualifiedLookUp(c, n, luf)

compiler/semtempl.nim

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,9 @@ proc symChoice(c: PContext, n: PNode, s: PSym, r: TSymChoiceRule;
6767
# for instance 'nextTry' is both in tables.nim and astalgo.nim ...
6868
if not isField or sfGenSym notin s.flags:
6969
result = newSymNode(s, info)
70-
if isField:
71-
# possibly not final field sym
72-
incl(s.flags, sfUsed)
73-
markOwnerModuleAsUsed(c, s)
74-
else:
75-
markUsed(c, info, s)
70+
# possibly not final field sym
71+
incl(s.flags, sfUsed)
72+
markOwnerModuleAsUsed(c, s)
7673
onUse(info, s)
7774
else:
7875
result = n

nimsuggest/tests/tqualified_highlight.nim

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ discard """
66
$nimsuggest --tester $file
77
>highlight $1
88
highlight;;skProc;;1;;7;;4
9-
highlight;;skProc;;1;;7;;4
10-
highlight;;skTemplate;;2;;7;;4
11-
highlight;;skTemplate;;2;;7;;4
129
highlight;;skTemplate;;2;;7;;4
1310
highlight;;skFunc;;3;;8;;1
1411
"""

tests/generics/toptions.nim

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
discard """
2+
matrix: "--warningAsError:Deprecated"
3+
"""
4+
5+
block: # bug #24905
6+
proc y() {.deprecated.} = discard
7+
proc v(_: int | int) =
8+
{.push warning[Deprecated]: off.}
9+
y()
10+
{.pop.}
11+
12+
v(1)
13+
14+
block: # bug #24903
15+
block:
16+
proc y() {.deprecated.} = discard
17+
proc m(_: int | int) =
18+
when false: y()
19+
20+
block:
21+
proc y() {.error.} = discard
22+
proc m(_: int | int) =
23+
when false: y()
24+
25+
block:
26+
proc y() {.error.} = discard
27+
proc m(_: int | int) =
28+
when true: y()
29+
30+
block: # bug #15650
31+
proc bar() {.deprecated.} = discard
32+
33+
template foo() =
34+
when false:
35+
bar()
36+
else:
37+
discard
38+
39+
foo()

0 commit comments

Comments
 (0)