summary refs log tree commit diff stats
path: root/tests/accept/compile
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2011-04-01 15:07:16 +0200
committerAraq <rumpf_a@web.de>2011-04-01 15:07:16 +0200
commit4741e8f9a1d1148d58e129626952219e14ede255 (patch)
treedb2eca2249ccc3230dc6c0a7359986198cab4048 /tests/accept/compile
parentdc669155e39007f1b584eef247dff90523f836bf (diff)
downloadNim-4741e8f9a1d1148d58e129626952219e14ede255.tar.gz
ugh, maybe broke git
Diffstat (limited to 'tests/accept/compile')
-rw-r--r--tests/accept/compile/tconstraints.nim15
-rw-r--r--tests/accept/compile/tgenericmatcher.nim19
-rw-r--r--tests/accept/compile/tgenericrefs.nim24
3 files changed, 58 insertions, 0 deletions
diff --git a/tests/accept/compile/tconstraints.nim b/tests/accept/compile/tconstraints.nim
new file mode 100644
index 000000000..7aef0d645
--- /dev/null
+++ b/tests/accept/compile/tconstraints.nim
@@ -0,0 +1,15 @@
+
+
+proc myGenericProc[T: object|tuple|int|ptr|ref|distinct](x: T): string = 
+  result = $x
+
+type
+  TMyObj = tuple[x, y: int]
+
+var
+  x: TMyObj
+
+assert myGenericProc(232) == "232"
+assert myGenericProc(x) == "(x: 0, y: 0)"
+
+
diff --git a/tests/accept/compile/tgenericmatcher.nim b/tests/accept/compile/tgenericmatcher.nim
new file mode 100644
index 000000000..eaf3da67c
--- /dev/null
+++ b/tests/accept/compile/tgenericmatcher.nim
@@ -0,0 +1,19 @@
+
+type
+  TMatcherKind = enum
+    mkTerminal, mkSequence, mkAlternation, mkRepeat
+  TMatcher[T] = object
+    case kind: TMatcherKind
+    of mkTerminal:
+      value: T
+    of mkSequence, mkAlternation:
+      matchers: seq[TMatcher[T]]
+    of mkRepeat:
+      matcher: PMatcher[T]
+      min, max: int
+  PMatcher[T] = ref TMatcher[T]
+
+var 
+  m: PMatcher[int]
+
+
diff --git a/tests/accept/compile/tgenericrefs.nim b/tests/accept/compile/tgenericrefs.nim
new file mode 100644
index 000000000..b0e77cef5
--- /dev/null
+++ b/tests/accept/compile/tgenericrefs.nim
@@ -0,0 +1,24 @@
+# Compiles:
+
+type 
+  TA[T] = object
+  PA[T] = ref TA[T]
+var a: PA[string]
+
+# Compiles unless you use var a: PA[string]
+type 
+  PA = ref TA
+  TA[T] = object
+
+
+# Cannot instanciate:
+type 
+  TA[T] = object
+    a: PA[T]
+  PA[T] = ref TA[T]
+
+type 
+  PA[T] = ref TA[T]
+  TA[T] = object
+
+