summary refs log tree commit diff stats
path: root/compiler/suggest.nim
diff options
context:
space:
mode:
authorNeelesh Chandola <neelesh.chandola@outlook.com>2018-12-30 14:15:39 +0530
committerAndreas Rumpf <rumpf_a@web.de>2018-12-30 09:45:39 +0100
commitcbbdcb266962df39bbdacb99ccd2a656ce9c3af7 (patch)
treed56c646ee7d1ab0f29ae587234c8735a986a1042 /compiler/suggest.nim
parentc5ad4c10cb976960a37656a55ad2fdbb0add8861 (diff)
downloadNim-cbbdcb266962df39bbdacb99ccd2a656ce9c3af7.tar.gz
Show deprecation warning for fields of a deprecated enum (#10112)
* Show deprecation warning for fields of a deprecated enum

* Add test
Diffstat (limited to 'compiler/suggest.nim')
-rw-r--r--compiler/suggest.nim11
1 files changed, 8 insertions, 3 deletions
diff --git a/compiler/suggest.nim b/compiler/suggest.nim
index dfa6e5ddb..f149327ac 100644
--- a/compiler/suggest.nim
+++ b/compiler/suggest.nim
@@ -462,14 +462,17 @@ proc extractPragma(s: PSym): PNode =
   doAssert result == nil or result.kind == nkPragma
 
 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:
     for it in pragmaNode:
       if whichPragma(it) == wDeprecated and it.safeLen == 2 and
           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
-  message(conf, info, warnDeprecated, s.name.s)
+  message(conf, info, warnDeprecated, name)
 
 proc userError(conf: ConfigRef; info: TLineInfo; s: PSym) =
   let pragmaNode = extractPragma(s)
@@ -486,6 +489,8 @@ proc markUsed(conf: ConfigRef; info: TLineInfo; s: PSym; usageSym: var PSym) =
   incl(s.flags, sfUsed)
   if s.kind == skEnumField and s.owner != nil:
     incl(s.owner.flags, sfUsed)
+    if sfDeprecated in s.owner.flags:
+      incl(s.flags, sfDeprecated)
   if {sfDeprecated, sfError} * s.flags != {}:
     if sfDeprecated in s.flags: warnAboutDeprecated(conf, info, s)
     if sfError in s.flags: userError(conf, info, s)