Skip to content

Commit

Permalink
ref nim-lang#20846; give a deprecation message for overriding = hook (
Browse files Browse the repository at this point in the history
nim-lang#21020)

give a deprecation message for overriding `=` hook
  • Loading branch information
ringabout authored and capocasa committed Mar 31, 2023
1 parent 625e33b commit bd688a0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions compiler/semstmts.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1881,6 +1881,8 @@ proc semOverride(c: PContext, s: PSym, n: PNode) =
if s.magic == mAsgn: return
incl(s.flags, sfUsed)
incl(s.flags, sfOverriden)
if name == "=":
message(c.config, n.info, warnDeprecated, "Overriding `=` hook is deprecated; Override `=copy` hook instead")
let t = s.typ
if t.len == 3 and t[0] == nil and t[1].kind == tyVar:
var obj = t[1][0]
Expand Down
11 changes: 11 additions & 0 deletions tests/deprecated/tequalhook.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
discard """
errormsg: "Overriding `=` hook is deprecated; Override `=copy` hook instead"
matrix: "--warningAsError[Deprecated]:on"
"""

type
SharedString = object
data: string

proc `=`(x: var SharedString, y: SharedString) =
discard

0 comments on commit bd688a0

Please sign in to comment.