summary refs log tree commit diff stats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/ccgbugs/tcodegenbug1.nim35
-rw-r--r--tests/openarray/t8259.nim7
-rw-r--r--tests/pragmas/tcustom_pragma.nim2
-rw-r--r--tests/stdlib/t8925.nim16
-rw-r--r--tests/vm/t4952.nim17
5 files changed, 75 insertions, 2 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
diff --git a/tests/openarray/t8259.nim b/tests/openarray/t8259.nim
new file mode 100644
index 000000000..40ff2b2f1
--- /dev/null
+++ b/tests/openarray/t8259.nim
@@ -0,0 +1,7 @@
+discard """
+  line: 6
+  errormsg: "invalid type: 'openarray[int]' for result"
+"""
+
+proc foo(a: openArray[int]):auto = a
+echo foo(toOpenArray([1, 2], 0, 2))
diff --git a/tests/pragmas/tcustom_pragma.nim b/tests/pragmas/tcustom_pragma.nim
index d7b199a22..ae0f39631 100644
--- a/tests/pragmas/tcustom_pragma.nim
+++ b/tests/pragmas/tcustom_pragma.nim
@@ -22,7 +22,7 @@ import custom_pragma
 block: # A bit more advanced case
   type
     Subfield {.defaultValue: "catman".} = object
-      c {.serializationKey: "cc".}: float
+      c* {.serializationKey: "cc".}: float
 
     MySerializable = object
       a {.serializationKey"asdf", defaultValue: 5.} : int
diff --git a/tests/stdlib/t8925.nim b/tests/stdlib/t8925.nim
new file mode 100644
index 000000000..d3dc1ea86
--- /dev/null
+++ b/tests/stdlib/t8925.nim
@@ -0,0 +1,16 @@
+discard """
+  file: "strscans.nim"
+  errormsg: "type mismatch between pattern '$i' (position: 1) and HourRange var 'hour'"
+"""
+
+import strscans
+
+type
+  HourRange = range[0..23]
+
+var
+  hour: HourRange
+  timeStr: string
+
+if scanf(timeStr, "$i", hour):
+  discard
diff --git a/tests/vm/t4952.nim b/tests/vm/t4952.nim
new file mode 100644
index 000000000..fc76fa4df
--- /dev/null
+++ b/tests/vm/t4952.nim
@@ -0,0 +1,17 @@
+import macros
+
+proc doCheck(tree: NimNode) =
+  let res: tuple[n: NimNode] = (n: tree)
+  assert: tree.kind == res.n.kind
+  for sub in tree:
+    doCheck(sub)
+
+macro id(body: untyped): untyped =
+  doCheck(body)
+
+id(foo((i: int)))
+
+static:
+  let tree = newTree(nnkExprColonExpr)
+  let t = (n: tree)
+  assert: t.n.kind == tree.kind