mirror of
https://github.com/nim-lang/Nim.git
synced 2026-06-18 17:41:21 +00:00
fixes #20846; warn on overloaded =copy with refc
This commit is contained in:
@@ -154,3 +154,4 @@ proc initDefines*(symbols: StringTableRef) =
|
||||
defineSymbol("nimHasGenericDefine")
|
||||
defineSymbol("nimHasDefineAliases")
|
||||
defineSymbol("nimHasWarnBareExcept")
|
||||
defineSymbol("nimHasWarnCopyHookForRefc")
|
||||
|
||||
@@ -88,6 +88,7 @@ type
|
||||
warnUnnamedBreak = "UnnamedBreak",
|
||||
warnStmtListLambda = "StmtListLambda",
|
||||
warnBareExcept = "BareExcept",
|
||||
warnCopyHookForRefc = "CopyHookForRefc",
|
||||
warnUser = "User",
|
||||
# hints
|
||||
hintSuccess = "Success", hintSuccessX = "SuccessX",
|
||||
@@ -189,6 +190,7 @@ const
|
||||
warnUnnamedBreak: "Using an unnamed break in a block is deprecated; Use a named block with a named break instead",
|
||||
warnStmtListLambda: "statement list expression assumed to be anonymous proc; this is deprecated, use `do (): ...` or `proc () = ...` instead",
|
||||
warnBareExcept: "$1",
|
||||
warnCopyHookForRefc: "Overriding `=copy` hook is not reliable for refc",
|
||||
warnUser: "$1",
|
||||
hintSuccess: "operation successful: $#",
|
||||
# keep in sync with `testament.isSuccess`
|
||||
|
||||
@@ -46,3 +46,7 @@ define:useStdoutAsStdmsg
|
||||
@if nimHasWarnBareExcept:
|
||||
warningAserror[BareExcept]:on
|
||||
@end
|
||||
|
||||
@if nimHasWarnCopyHookForRefc:
|
||||
warningAserror[CopyHookForRefc]:on
|
||||
@end
|
||||
|
||||
@@ -1857,6 +1857,8 @@ proc semOverride(c: PContext, s: PSym, n: PNode) =
|
||||
incl(s.flags, sfOverriden)
|
||||
if name == "=":
|
||||
message(c.config, n.info, warnDeprecated, "Overriding `=` hook is deprecated; Override `=copy` hook instead")
|
||||
elif name == "=copy" and c.config.selectedGC == gcRefc:
|
||||
message(c.config, n.info, warnCopyHookForRefc)
|
||||
let t = s.typ
|
||||
if t.len == 3 and t[0] == nil and t[1].kind == tyVar:
|
||||
var obj = t[1][0]
|
||||
|
||||
Reference in New Issue
Block a user