summary refs log tree commit diff stats
path: root/tests
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2018-09-18 09:36:16 +0200
committerGitHub <noreply@github.com>2018-09-18 09:36:16 +0200
commitc661f8e1be24a4d3d4b9cf8a544e2a3cdca87593 (patch)
treed65dfc0998432089c8f966c6506e72a376f12477 /tests
parent9c6dde1b707b1ccc58c183047ee149a6c70b7e10 (diff)
parentacaf2b8e76e1c3e1a63228bed535b33aa20b0f1d (diff)
downloadNim-c661f8e1be24a4d3d4b9cf8a544e2a3cdca87593.tar.gz
Merge pull request #8983 from cooldome/codegen_crash
Fixes 8979
Diffstat (limited to 'tests')
-rw-r--r--tests/ccgbugs/tcodegenbug1.nim35
1 files changed, 34 insertions, 1 deletions
diff --git a/tests/ccgbugs/tcodegenbug1.nim b/tests/ccgbugs/tcodegenbug1.nim
index fce74de0c..012a4de47 100644
--- a/tests/ccgbugs/tcodegenbug1.nim
+++ b/tests/ccgbugs/tcodegenbug1.nim
@@ -2,7 +2,8 @@ discard """
   output: '''obj = (inner: (kind: Just, id: 7))
 obj.inner.id = 7
 id = 7
-obj = (inner: (kind: Just, id: 7))'''
+obj = (inner: (kind: Just, id: 7))
+2'''
 """
 
 # bug #6960
@@ -105,3 +106,35 @@ type
 
 proc bug5137(d: MyIntDistinct) =
   discard d.MyInt
+
+#-------------------------------------
+# bug #8979
+
+type
+  MyKind = enum
+    Fixed, Float
+
+  MyObject = object
+    someInt: int
+    case kind: MyKind
+      of Float: index: string
+      of Fixed: nil
+
+  MyResult = object
+    val: array[0..1, string]
+    vis: set[0..1]
+
+import macros
+
+func myfunc(obj: MyObject): MyResult {.raises: [].} =
+  template index: auto =
+    case obj.kind:
+      of Float: $obj.index 
+      of Fixed: "Fixed"
+  macro to_str(a: untyped): string =
+    result = newStrLitNode(a.repr)  
+  result.val[0] = index
+  result.val[1] = to_str(obj.kind + Ola)
+
+let x = MyObject(someInt: 10, kind: Fixed)
+echo myfunc(x).val.len