Compare commits

...

3 Commits

Author SHA1 Message Date
ringabout
5c4a5421b5 Merge branch 'devel' into pr_refc_copy 2023-04-13 18:17:42 +08:00
ringabout
ebb931f9f4 check refc first 2023-04-03 14:39:17 +08:00
ringabout
273d5ddf17 fixes #20846; warn on overloaded =copy with refc 2023-04-03 14:38:20 +08:00
4 changed files with 9 additions and 0 deletions

View File

@@ -154,3 +154,4 @@ proc initDefines*(symbols: StringTableRef) =
defineSymbol("nimHasGenericDefine")
defineSymbol("nimHasDefineAliases")
defineSymbol("nimHasWarnBareExcept")
defineSymbol("nimHasWarnCopyHookForRefc")

View File

@@ -88,6 +88,7 @@ type
warnUnnamedBreak = "UnnamedBreak",
warnStmtListLambda = "StmtListLambda",
warnBareExcept = "BareExcept",
warnCopyHookForRefc = "CopyHookForRefc",
warnImplicitDefaultValue = "ImplicitDefaultValue",
warnUser = "User",
# hints
@@ -190,6 +191,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",
warnImplicitDefaultValue: "$1",
warnUser: "$1",
hintSuccess: "operation successful: $#",

View File

@@ -46,3 +46,7 @@ define:useStdoutAsStdmsg
@if nimHasWarnBareExcept:
warningAserror[BareExcept]:on
@end
@if nimHasWarnCopyHookForRefc:
warningAserror[CopyHookForRefc]:on
@end

View File

@@ -1886,6 +1886,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 c.config.selectedGC == gcRefc and name == "=copy":
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]