summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--changelog.md9
-rw-r--r--compiler/pragmas.nim5
-rw-r--r--compiler/suggest.nim14
-rw-r--r--compiler/trees.nim2
-rw-r--r--lib/system.nim1
5 files changed, 27 insertions, 4 deletions
diff --git a/changelog.md b/changelog.md
index c2211b510..a3f16738f 100644
--- a/changelog.md
+++ b/changelog.md
@@ -238,3 +238,12 @@ styledEcho "Red on Green.", resetStyle
 - Type inference for generic type parameters involving numeric types is now symetric. See
   [Generic type inference for numeric types](https://nim-lang.org/docs/manual.html#generics-generic-type-inference-fornumeric-types)
   for more information.
+- The ``deprecated`` pragma now supports a user-definable warning message for procs.
+
+```nim
+
+proc bar {.deprecated: "use foo instead".} =
+  return
+
+bar()
+```
diff --git a/compiler/pragmas.nim b/compiler/pragmas.nim
index cf289a506..d52d8b614 100644
--- a/compiler/pragmas.nim
+++ b/compiler/pragmas.nim
@@ -810,7 +810,10 @@ proc singlePragma(c: PContext, sym: PSym, n: PNode, i: int,
       of wExplain:
         sym.flags.incl sfExplain
       of wDeprecated:
-        if it.kind in nkPragmaCallKinds: deprecatedStmt(c, it)
+        if sym != nil and sym.kind in routineKinds:
+          if it.kind in nkPragmaCallKinds: discard getStrLitNode(c, it)
+          incl(sym.flags, sfDeprecated)
+        elif it.kind in nkPragmaCallKinds: deprecatedStmt(c, it)
         elif sym != nil: incl(sym.flags, sfDeprecated)
         else: incl(c.module.flags, sfDeprecated)
       of wVarargs:
diff --git a/compiler/suggest.nim b/compiler/suggest.nim
index 28ce3c591..af31495aa 100644
--- a/compiler/suggest.nim
+++ b/compiler/suggest.nim
@@ -33,6 +33,7 @@
 # included from sigmatch.nim
 
 import algorithm, prefixmatches
+from wordrecg import wDeprecated
 
 when defined(nimsuggest):
   import passes, tables # importer
@@ -479,12 +480,23 @@ proc suggestSym*(info: TLineInfo; s: PSym; usageSym: var PSym; isDecl=true) {.in
         isDecl:
       suggestResult(symToSuggest(s, isLocal=false, ideOutline, info, 100, PrefixMatch.None, false, 0))
 
+proc warnAboutDeprecated(info: TLineInfo; s: PSym) =
+  if s.kind in routineKinds:
+    let n = s.ast[pragmasPos]
+    if n.kind != nkEmpty:
+      for it in n:
+        if whichPragma(it) == wDeprecated and it.safeLen == 2 and
+            it[1].kind in {nkStrLit..nkTripleStrLit}:
+          message(info, warnDeprecated, it[1].strVal & "; " & s.name.s)
+          return
+  message(info, warnDeprecated, s.name.s)
+
 proc markUsed(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, sfError} * s.flags != {}:
-    if sfDeprecated in s.flags: message(info, warnDeprecated, s.name.s)
+    if sfDeprecated in s.flags: warnAboutDeprecated(info, s)
     if sfError in s.flags: localError(info, errWrongSymbolX, s.name.s)
   when defined(nimsuggest):
     suggestSym(info, s, usageSym, false)
diff --git a/compiler/trees.nim b/compiler/trees.nim
index 577ea75ee..f69108942 100644
--- a/compiler/trees.nim
+++ b/compiler/trees.nim
@@ -118,7 +118,7 @@ proc isRange*(n: PNode): bool {.inline.} =
       result = true
 
 proc whichPragma*(n: PNode): TSpecialWord =
-  let key = if n.kind == nkExprColonExpr: n.sons[0] else: n
+  let key = if n.kind in nkPragmaCallKinds and n.len > 0: n.sons[0] else: n
   if key.kind == nkIdent: result = whichKeyword(key.ident)
 
 proc unnestStmts(n, result: PNode) =
diff --git a/lib/system.nim b/lib/system.nim
index 079b06b48..63511f71c 100644
--- a/lib/system.nim
+++ b/lib/system.nim
@@ -3769,7 +3769,6 @@ proc failedAssertImpl*(msg: string) {.raises: [], tags: [].} =
   # by ``assert``.
   type Hide = proc (msg: string) {.noinline, raises: [], noSideEffect,
                                     tags: [].}
-  {.deprecated: [THide: Hide].}
   Hide(raiseAssert)(msg)
 
 template assert*(cond: bool, msg = "") =