* 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:
parent
f8519657c4
commit
70fb377e88
5 changed files with 10 additions and 15 deletions
|
|
@ -23,15 +23,14 @@
|
||||||
- `repr` now doesn't insert trailing newline; previous behavior was very inconsistent,
|
- `repr` now doesn't insert trailing newline; previous behavior was very inconsistent,
|
||||||
see #16034. Use `-d:nimLegacyReprWithNewline` for previous behavior.
|
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
|
- A type conversion from one enum type to another now produces an `[EnumConv]` warning.
|
||||||
compiler won't help if you misuse it).
|
You should use `ord` (or `cast`, but the compiler won't help, if you misuse it) instead.
|
||||||
```
|
```
|
||||||
type A = enum a1, a2
|
type A = enum a1, a2
|
||||||
type B = enum b1, b2
|
type B = enum b1, b2
|
||||||
doAssert not compiles(a1.B)
|
echo a1.B # produces a warning
|
||||||
doAssert compiles(a1.ord.B)
|
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
|
- Type mismatch errors now show more context, use `-d:nimLegacyTypeMismatch` for previous
|
||||||
behavior.
|
behavior.
|
||||||
|
|
|
||||||
|
|
@ -70,6 +70,7 @@ type
|
||||||
warnResultUsed = "ResultUsed",
|
warnResultUsed = "ResultUsed",
|
||||||
warnCannotOpen = "CannotOpen",
|
warnCannotOpen = "CannotOpen",
|
||||||
warnFileChanged = "FileChanged",
|
warnFileChanged = "FileChanged",
|
||||||
|
warnSuspiciousEnumConv = "EnumConv",
|
||||||
warnUser = "User",
|
warnUser = "User",
|
||||||
# hints
|
# hints
|
||||||
hintSuccess = "Success", hintSuccessX = "SuccessX",
|
hintSuccess = "Success", hintSuccessX = "SuccessX",
|
||||||
|
|
@ -153,6 +154,7 @@ const
|
||||||
warnResultUsed: "used 'result' variable",
|
warnResultUsed: "used 'result' variable",
|
||||||
warnCannotOpen: "cannot open: $1",
|
warnCannotOpen: "cannot open: $1",
|
||||||
warnFileChanged: "file changed: $1",
|
warnFileChanged: "file changed: $1",
|
||||||
|
warnSuspiciousEnumConv: "$1",
|
||||||
warnUser: "$1",
|
warnUser: "$1",
|
||||||
hintSuccess: "operation successful: $#",
|
hintSuccess: "operation successful: $#",
|
||||||
# keep in sync with `testament.isSuccess`
|
# 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
|
elif (targetBaseTyp.kind in IntegralTypes) and
|
||||||
(srcBaseTyp.kind in IntegralTypes):
|
(srcBaseTyp.kind in IntegralTypes):
|
||||||
if targetTyp.kind == tyEnum and srcBaseTyp.kind == tyEnum:
|
if targetTyp.kind == tyEnum and srcBaseTyp.kind == tyEnum:
|
||||||
if c.config.isDefined("nimLegacyConvEnumEnum"):
|
message(c.config, src.info, warnSuspiciousEnumConv, "suspicious code: enum to enum conversion")
|
||||||
message(c.config, src.info, warnUser, "enum to enum conversion is now deprecated")
|
|
||||||
else: result = convNotLegal
|
|
||||||
# `elif` would be incorrect here
|
# `elif` would be incorrect here
|
||||||
if targetTyp.kind == tyBool:
|
if targetTyp.kind == tyBool:
|
||||||
discard "convOk"
|
discard "convOk"
|
||||||
|
|
|
||||||
|
|
@ -1598,8 +1598,6 @@ proc typeMismatch*(conf: ConfigRef; info: TLineInfo, formal, actual: PType, n: P
|
||||||
of efLockLevelsDiffer:
|
of efLockLevelsDiffer:
|
||||||
msg.add "\nlock levels differ"
|
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)
|
localError(conf, info, msg)
|
||||||
|
|
||||||
proc isTupleRecursive(t: PType, cycleDetector: var IntSet): bool =
|
proc isTupleRecursive(t: PType, cycleDetector: var IntSet): bool =
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
discard """
|
discard """
|
||||||
nimout:'''
|
matrix: "--warningAsError:EnumConv"
|
||||||
tconv.nim(81, 15) Warning: enum to enum conversion is now deprecated [User]
|
|
||||||
'''
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
template reject(x) =
|
template reject(x) =
|
||||||
|
|
@ -77,12 +75,12 @@ block: # https://github.com/nim-lang/RFCs/issues/294
|
||||||
reject: k2.Goo
|
reject: k2.Goo
|
||||||
reject: k2.string
|
reject: k2.string
|
||||||
|
|
||||||
{.define(nimLegacyConvEnumEnum).}
|
{.push warningAsError[EnumConv]:off.}
|
||||||
discard Goo(k2)
|
discard Goo(k2)
|
||||||
accept: Goo(k2)
|
accept: Goo(k2)
|
||||||
accept: k2.Goo
|
accept: k2.Goo
|
||||||
reject: k2.string
|
reject: k2.string
|
||||||
{.undef(nimLegacyConvEnumEnum).}
|
{.pop.}
|
||||||
|
|
||||||
reject: Goo(k2)
|
reject: Goo(k2)
|
||||||
reject: k2.Goo
|
reject: k2.Goo
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue