diff options
author | ringabout <43030857+ringabout@users.noreply.github.com> | 2022-12-05 14:13:51 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-05 07:13:51 +0100 |
commit | 6f96c4bc96be60e494d22c58df2f16f6f5890732 (patch) | |
tree | 7951e0b29dfc393436ac067dbe926cc94ad87de2 | |
parent | 1b5e03f975a9e02c217ece12b02ba483fa1e5cc0 (diff) | |
download | Nim-6f96c4bc96be60e494d22c58df2f16f6f5890732.tar.gz |
ref #20846; give a deprecation message for overriding `=` hook (#21020)
give a deprecation message for overriding `=` hook
-rw-r--r-- | compiler/semstmts.nim | 2 | ||||
-rw-r--r-- | tests/deprecated/tequalhook.nim | 11 |
2 files changed, 13 insertions, 0 deletions
diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index cbc633383..f1875a3d8 100644 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -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] diff --git a/tests/deprecated/tequalhook.nim b/tests/deprecated/tequalhook.nim new file mode 100644 index 000000000..79ee835f8 --- /dev/null +++ b/tests/deprecated/tequalhook.nim @@ -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 \ No newline at end of file |