{.deprecated: msg.} now works for vars and lets (#10234)
This commit is contained in:
parent
d0366c5194
commit
fb26b95f81
4 changed files with 16 additions and 10 deletions
|
|
@ -881,7 +881,7 @@ proc singlePragma(c: PContext, sym: PSym, n: PNode, i: var int,
|
||||||
of wExplain:
|
of wExplain:
|
||||||
sym.flags.incl sfExplain
|
sym.flags.incl sfExplain
|
||||||
of wDeprecated:
|
of wDeprecated:
|
||||||
if sym != nil and sym.kind in routineKinds + {skType}:
|
if sym != nil and sym.kind in routineKinds + {skType, skVar, skLet}:
|
||||||
if it.kind in nkPragmaCallKinds: discard getStrLitNode(c, it)
|
if it.kind in nkPragmaCallKinds: discard getStrLitNode(c, it)
|
||||||
incl(sym.flags, sfDeprecated)
|
incl(sym.flags, sfDeprecated)
|
||||||
elif sym != nil and sym.kind != skModule:
|
elif sym != nil and sym.kind != skModule:
|
||||||
|
|
|
||||||
|
|
@ -456,13 +456,17 @@ proc suggestSym*(conf: ConfigRef; info: TLineInfo; s: PSym; usageSym: var PSym;
|
||||||
proc extractPragma(s: PSym): PNode =
|
proc extractPragma(s: PSym): PNode =
|
||||||
if s.kind in routineKinds:
|
if s.kind in routineKinds:
|
||||||
result = s.ast[pragmasPos]
|
result = s.ast[pragmasPos]
|
||||||
elif s.kind in {skType}:
|
elif s.kind in {skType, skVar, skLet}:
|
||||||
# s.ast = nkTypedef / nkPragmaExpr / [nkSym, nkPragma]
|
# s.ast = nkTypedef / nkPragmaExpr / [nkSym, nkPragma]
|
||||||
result = s.ast[0][1]
|
result = s.ast[0][1]
|
||||||
doAssert result == nil or result.kind == nkPragma
|
doAssert result == nil or result.kind == nkPragma
|
||||||
|
|
||||||
proc warnAboutDeprecated(conf: ConfigRef; info: TLineInfo; s: PSym) =
|
proc warnAboutDeprecated(conf: ConfigRef; info: TLineInfo; s: PSym) =
|
||||||
let pragmaNode = if s.kind == skEnumField: extractPragma(s.owner) else: extractPragma(s)
|
var pragmaNode: PNode
|
||||||
|
if optOldAst in conf.options and s.kind in {skVar, skLet}:
|
||||||
|
pragmaNode = nil
|
||||||
|
else:
|
||||||
|
pragmaNode = if s.kind == skEnumField: extractPragma(s.owner) else: extractPragma(s)
|
||||||
let name =
|
let name =
|
||||||
if s.kind == skEnumField and sfDeprecated notin s.flags: "enum '" & s.owner.name.s & "' which contains field '" & s.name.s & "'"
|
if s.kind == skEnumField and sfDeprecated notin s.flags: "enum '" & s.owner.name.s & "' which contains field '" & s.name.s & "'"
|
||||||
else: s.name.s
|
else: s.name.s
|
||||||
|
|
|
||||||
9
tests/deprecated/tannot.nim
Normal file
9
tests/deprecated/tannot.nim
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
discard """
|
||||||
|
nimout: '''tannot.nim(9, 1) Warning: efgh; foo1 is deprecated [Deprecated]
|
||||||
|
tannot.nim(9, 8) Warning: abcd; foo is deprecated [Deprecated]
|
||||||
|
'''
|
||||||
|
"""
|
||||||
|
|
||||||
|
let foo* {.deprecated: "abcd".} = 42
|
||||||
|
var foo1* {.deprecated: "efgh".} = 42
|
||||||
|
foo1 = foo
|
||||||
|
|
@ -1,7 +0,0 @@
|
||||||
discard """
|
|
||||||
errormsg: "annotation to deprecated not supported here"
|
|
||||||
line: 7
|
|
||||||
"""
|
|
||||||
|
|
||||||
var foo* {.deprecated.} = 42
|
|
||||||
var foo1* {.deprecated: "no".} = 42
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue