Show deprecation warning for fields of a deprecated enum (#10112)
* Show deprecation warning for fields of a deprecated enum * Add test
This commit is contained in:
parent
c5ad4c10cb
commit
cbbdcb2669
2 changed files with 22 additions and 7 deletions
|
|
@ -462,14 +462,17 @@ proc extractPragma(s: PSym): PNode =
|
||||||
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 = extractPragma(s)
|
let pragmaNode = if s.kind == skEnumField: extractPragma(s.owner) else: extractPragma(s)
|
||||||
|
let name =
|
||||||
|
if s.kind == skEnumField: "enum '" & s.owner.name.s & "' which contains field '" & s.name.s & "'"
|
||||||
|
else: s.name.s
|
||||||
if pragmaNode != nil:
|
if pragmaNode != nil:
|
||||||
for it in pragmaNode:
|
for it in pragmaNode:
|
||||||
if whichPragma(it) == wDeprecated and it.safeLen == 2 and
|
if whichPragma(it) == wDeprecated and it.safeLen == 2 and
|
||||||
it[1].kind in {nkStrLit..nkTripleStrLit}:
|
it[1].kind in {nkStrLit..nkTripleStrLit}:
|
||||||
message(conf, info, warnDeprecated, it[1].strVal & "; " & s.name.s)
|
message(conf, info, warnDeprecated, it[1].strVal & "; " & name)
|
||||||
return
|
return
|
||||||
message(conf, info, warnDeprecated, s.name.s)
|
message(conf, info, warnDeprecated, name)
|
||||||
|
|
||||||
proc userError(conf: ConfigRef; info: TLineInfo; s: PSym) =
|
proc userError(conf: ConfigRef; info: TLineInfo; s: PSym) =
|
||||||
let pragmaNode = extractPragma(s)
|
let pragmaNode = extractPragma(s)
|
||||||
|
|
@ -486,6 +489,8 @@ proc markUsed(conf: ConfigRef; info: TLineInfo; s: PSym; usageSym: var PSym) =
|
||||||
incl(s.flags, sfUsed)
|
incl(s.flags, sfUsed)
|
||||||
if s.kind == skEnumField and s.owner != nil:
|
if s.kind == skEnumField and s.owner != nil:
|
||||||
incl(s.owner.flags, sfUsed)
|
incl(s.owner.flags, sfUsed)
|
||||||
|
if sfDeprecated in s.owner.flags:
|
||||||
|
incl(s.flags, sfDeprecated)
|
||||||
if {sfDeprecated, sfError} * s.flags != {}:
|
if {sfDeprecated, sfError} * s.flags != {}:
|
||||||
if sfDeprecated in s.flags: warnAboutDeprecated(conf, info, s)
|
if sfDeprecated in s.flags: warnAboutDeprecated(conf, info, s)
|
||||||
if sfError in s.flags: userError(conf, info, s)
|
if sfError in s.flags: userError(conf, info, s)
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,19 @@
|
||||||
discard """
|
discard """
|
||||||
nimout: "a is deprecated [Deprecated]"
|
nimout: '''tdeprecated.nim(10, 3) Warning: a is deprecated [Deprecated]
|
||||||
|
tdeprecated.nim(17, 11) Warning: asdf; enum 'Foo' which contains field 'a' is deprecated [Deprecated]
|
||||||
|
'''
|
||||||
"""
|
"""
|
||||||
|
block:
|
||||||
|
var
|
||||||
|
a {.deprecated.}: array[0..11, int]
|
||||||
|
|
||||||
var
|
a[8] = 1
|
||||||
a {.deprecated.}: array[0..11, int]
|
|
||||||
|
|
||||||
a[8] = 1
|
block t10111:
|
||||||
|
type
|
||||||
|
Foo {.deprecated: "asdf" .} = enum
|
||||||
|
a
|
||||||
|
|
||||||
|
var _ = a
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue