mirror of
https://github.com/nim-lang/Nim.git
synced 2026-02-13 23:03:36 +00:00
* undo RFC #294, it breaks code for no good reason, the compiler can warn about the construct instead * Update changelog.md Co-authored-by: konsumlamm <44230978+konsumlamm@users.noreply.github.com> * enable test case Co-authored-by: konsumlamm <44230978+konsumlamm@users.noreply.github.com>
This commit is contained in:
@@ -23,15 +23,14 @@
|
||||
- `repr` now doesn't insert trailing newline; previous behavior was very inconsistent,
|
||||
see #16034. Use `-d:nimLegacyReprWithNewline` for previous behavior.
|
||||
|
||||
- An enum now can't be converted to another enum directly, you must use `ord` (or `cast`, but
|
||||
compiler won't help if you misuse it).
|
||||
- A type conversion from one enum type to another now produces an `[EnumConv]` warning.
|
||||
You should use `ord` (or `cast`, but the compiler won't help, if you misuse it) instead.
|
||||
```
|
||||
type A = enum a1, a2
|
||||
type B = enum b1, b2
|
||||
doAssert not compiles(a1.B)
|
||||
doAssert compiles(a1.ord.B)
|
||||
echo a1.B # produces a warning
|
||||
echo a1.ord.B # produces no warning
|
||||
```
|
||||
for a transition period, use `-d:nimLegacyConvEnumEnum`.
|
||||
|
||||
- Type mismatch errors now show more context, use `-d:nimLegacyTypeMismatch` for previous
|
||||
behavior.
|
||||
|
||||
@@ -70,6 +70,7 @@ type
|
||||
warnResultUsed = "ResultUsed",
|
||||
warnCannotOpen = "CannotOpen",
|
||||
warnFileChanged = "FileChanged",
|
||||
warnSuspiciousEnumConv = "EnumConv",
|
||||
warnUser = "User",
|
||||
# hints
|
||||
hintSuccess = "Success", hintSuccessX = "SuccessX",
|
||||
@@ -153,6 +154,7 @@ const
|
||||
warnResultUsed: "used 'result' variable",
|
||||
warnCannotOpen: "cannot open: $1",
|
||||
warnFileChanged: "file changed: $1",
|
||||
warnSuspiciousEnumConv: "$1",
|
||||
warnUser: "$1",
|
||||
hintSuccess: "operation successful: $#",
|
||||
# keep in sync with `testament.isSuccess`
|
||||
|
||||
@@ -168,9 +168,7 @@ proc checkConvertible(c: PContext, targetTyp: PType, src: PNode): TConvStatus =
|
||||
elif (targetBaseTyp.kind in IntegralTypes) and
|
||||
(srcBaseTyp.kind in IntegralTypes):
|
||||
if targetTyp.kind == tyEnum and srcBaseTyp.kind == tyEnum:
|
||||
if c.config.isDefined("nimLegacyConvEnumEnum"):
|
||||
message(c.config, src.info, warnUser, "enum to enum conversion is now deprecated")
|
||||
else: result = convNotLegal
|
||||
message(c.config, src.info, warnSuspiciousEnumConv, "suspicious code: enum to enum conversion")
|
||||
# `elif` would be incorrect here
|
||||
if targetTyp.kind == tyBool:
|
||||
discard "convOk"
|
||||
|
||||
@@ -1598,8 +1598,6 @@ proc typeMismatch*(conf: ConfigRef; info: TLineInfo, formal, actual: PType, n: P
|
||||
of efLockLevelsDiffer:
|
||||
msg.add "\nlock levels differ"
|
||||
|
||||
if formal.kind == tyEnum and actual.kind == tyEnum:
|
||||
msg.add "\nmaybe use `-d:nimLegacyConvEnumEnum` for a transition period"
|
||||
localError(conf, info, msg)
|
||||
|
||||
proc isTupleRecursive(t: PType, cycleDetector: var IntSet): bool =
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
discard """
|
||||
nimout:'''
|
||||
tconv.nim(81, 15) Warning: enum to enum conversion is now deprecated [User]
|
||||
'''
|
||||
matrix: "--warningAsError:EnumConv"
|
||||
"""
|
||||
|
||||
template reject(x) =
|
||||
@@ -77,12 +75,12 @@ block: # https://github.com/nim-lang/RFCs/issues/294
|
||||
reject: k2.Goo
|
||||
reject: k2.string
|
||||
|
||||
{.define(nimLegacyConvEnumEnum).}
|
||||
{.push warningAsError[EnumConv]:off.}
|
||||
discard Goo(k2)
|
||||
accept: Goo(k2)
|
||||
accept: k2.Goo
|
||||
reject: k2.string
|
||||
{.undef(nimLegacyConvEnumEnum).}
|
||||
{.pop.}
|
||||
|
||||
reject: Goo(k2)
|
||||
reject: k2.Goo
|
||||
|
||||
Reference in New Issue
Block a user