mirror of
https://github.com/nim-lang/Nim.git
synced 2026-05-03 20:44:46 +00:00
* mitigates #12815 * Update doc/nimc.rst Co-authored-by: konsumlamm <44230978+konsumlamm@users.noreply.github.com> Co-authored-by: konsumlamm <44230978+konsumlamm@users.noreply.github.com>
This commit is contained in:
@@ -72,6 +72,7 @@ type
|
||||
warnFileChanged = "FileChanged",
|
||||
warnSuspiciousEnumConv = "EnumConv",
|
||||
warnAnyEnumConv = "AnyEnumConv",
|
||||
warnHoleEnumConv = "HoleEnumConv",
|
||||
warnCstringConv = "CStringConv",
|
||||
warnUser = "User",
|
||||
# hints
|
||||
@@ -158,6 +159,7 @@ const
|
||||
warnFileChanged: "file changed: $1",
|
||||
warnSuspiciousEnumConv: "$1",
|
||||
warnAnyEnumConv: "$1",
|
||||
warnHoleEnumConv: "$1",
|
||||
warnCstringConv: "$1",
|
||||
warnUser: "$1",
|
||||
hintSuccess: "operation successful: $#",
|
||||
|
||||
@@ -1173,8 +1173,12 @@ proc track(tracked: PEffects, n: PNode) =
|
||||
"implicit conversion to 'cstring' from a non-const location: $1; this will become a compile time error in the future" %
|
||||
$n[1])
|
||||
|
||||
if n.typ.skipTypes(abstractInst).kind == tyEnum:
|
||||
message(tracked.config, n.info, warnAnyEnumConv, "enum conversion: $1" % $n[1])
|
||||
let t = n.typ.skipTypes(abstractInst)
|
||||
if t.kind == tyEnum:
|
||||
if tfEnumHasHoles in t.flags:
|
||||
message(tracked.config, n.info, warnHoleEnumConv, "conversion to enum with holes is unsafe: $1" % $n)
|
||||
else:
|
||||
message(tracked.config, n.info, warnAnyEnumConv, "enum conversion: $1" % $n)
|
||||
|
||||
if n.len == 2:
|
||||
track(tracked, n[1])
|
||||
|
||||
@@ -74,6 +74,8 @@ CStringConv Warn about dangerous implicit conversions
|
||||
to `cstring`.
|
||||
EnumConv Warn about conversions from enum to enum.
|
||||
AnyEnumConv Warn about any conversions to an enum type.
|
||||
HoleEnumConv Warn about conversion to an enum with
|
||||
holes. These conversions are unsafe.
|
||||
ResultUsed Warn about the usage of the
|
||||
built-in `result` variable.
|
||||
User Some user-defined warning.
|
||||
|
||||
@@ -95,13 +95,26 @@ reject:
|
||||
{.push warning[AnyEnumConv]:on, warningAsError[AnyEnumConv]:on.}
|
||||
|
||||
reject:
|
||||
# bug #12815
|
||||
type
|
||||
Foo = enum
|
||||
one = 1
|
||||
three = 3
|
||||
one
|
||||
three
|
||||
|
||||
var va = 2
|
||||
var vb = va.Foo
|
||||
|
||||
{.pop.}
|
||||
|
||||
{.push warningAsError[HoleEnumConv]:on.}
|
||||
|
||||
reject:
|
||||
# bug #12815
|
||||
type
|
||||
Hole = enum
|
||||
one = 1
|
||||
three = 3
|
||||
|
||||
var va = 2
|
||||
var vb = va.Hole
|
||||
|
||||
{.pop.}
|
||||
|
||||
Reference in New Issue
Block a user