summary refs log tree commit diff stats
path: root/tests/misc/tconv.nim
diff options
context:
space:
mode:
authorTimothee Cour <timothee.cour2@gmail.com>2021-04-02 22:15:21 -0700
committerGitHub <noreply@github.com>2021-04-03 07:15:21 +0200
commit270964c487e5347c61dade25bec903580483dda5 (patch)
treeed6f3dfdde633b99b1b0b402c41b7cbeb75011a5 /tests/misc/tconv.nim
parenta807233aebcd3759bc3e21b450ed89e1eb6ddace (diff)
downloadNim-270964c487e5347c61dade25bec903580483dda5.tar.gz
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
Diffstat (limited to 'tests/misc/tconv.nim')
-rw-r--r--tests/misc/tconv.nim33
1 files changed, 32 insertions, 1 deletions
diff --git a/tests/misc/tconv.nim b/tests/misc/tconv.nim
index f7d15b0b5..c93fc57f8 100644
--- a/tests/misc/tconv.nim
+++ b/tests/misc/tconv.nim
@@ -1,5 +1,13 @@
+discard """
+  nimout:'''
+tconv.nim(81, 15) Warning: enum to enum conversion is now deprecated [User]
+'''
+"""
+
 template reject(x) =
-    static: assert(not compiles(x))
+  static: doAssert(not compiles(x))
+template accept(x) =
+  static: doAssert(compiles(x))
 
 reject:
     const x = int8(300)
@@ -55,3 +63,26 @@ block: # issue 3766
     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