Files
Nim/tests/misc/tconv.nim
Timothee Cour 270964c487 implement RFCs/294 ; disallow enum <=> enum conversion (#16351)
* fix https://github.com/nim-lang/RFCs/issues/294 ; disallow enum <=> enum conversion
* fix the runnableExamples that was the instigator of this RFC
* legacy -d:nimLegacyConvEnumEnum
* use -d:nimLegacyConvEnumEnum in important_package nimgame2
* add test for enum cast
* improve changelog
* add changelog: Changes affecting backward compatibility
* cleanup changelog
* fix changelog
2021-04-03 07:15:21 +02:00

89 lines
1.2 KiB
Nim

discard """
nimout:'''
tconv.nim(81, 15) Warning: enum to enum conversion is now deprecated [User]
'''
"""
template reject(x) =
static: doAssert(not compiles(x))
template accept(x) =
static: doAssert(compiles(x))
reject:
const x = int8(300)
reject:
const x = int64(NaN)
type
R = range[0..10]
reject:
const x = R(11)
reject:
const x = R(11.0)
reject:
const x = R(NaN)
reject:
const x = R(Inf)
type
FloatRange = range[0'f..10'f]
reject:
const x = FloatRange(-1'f)
reject:
const x = FloatRange(-1)
reject:
const x = FloatRange(NaN)
block:
const x = float32(NaN)
type E = enum a, b, c
reject:
const e = E(4)
block: # issue 3766
type R = range[0..2]
reject:
type
T[n: static[R]] = object
V = T[3.R]
reject:
proc r(x: static[R]) =
echo x
r 3.R
block: # https://github.com/nim-lang/RFCs/issues/294
type Koo = enum k1, k2
type Goo = enum g1, g2
accept: Koo(k2)
accept: k2.Koo
accept: k2.int.Goo
reject: Goo(k2)
reject: k2.Goo
reject: k2.string
{.define(nimLegacyConvEnumEnum).}
discard Goo(k2)
accept: Goo(k2)
accept: k2.Goo
reject: k2.string
{.undef(nimLegacyConvEnumEnum).}
reject: Goo(k2)
reject: k2.Goo