summary refs log tree commit diff stats
path: root/tests/alias
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2014-01-13 02:10:03 +0100
committerAraq <rumpf_a@web.de>2014-01-13 02:10:03 +0100
commit20b5f31c03fb556ec0aa2428a40adbac004d8987 (patch)
tree58086941e7d6bb8f480ca1173a95722ada9435b2 /tests/alias
parent51ee524109cf7e3e86c676bc1676063a01bfd979 (diff)
downloadNim-20b5f31c03fb556ec0aa2428a40adbac004d8987.tar.gz
new tester; all tests categorized
Diffstat (limited to 'tests/alias')
-rw-r--r--tests/alias/talias.nim66
1 files changed, 66 insertions, 0 deletions
diff --git a/tests/alias/talias.nim b/tests/alias/talias.nim
new file mode 100644
index 000000000..819289c2e
--- /dev/null
+++ b/tests/alias/talias.nim
@@ -0,0 +1,66 @@
+# Test the alias analysis
+
+type
+  TAnalysisResult* = enum
+    arNo, arMaybe, arYes
+
+proc isPartOf*[S, T](a: S, b: T): TAnalysisResult {.
+  magic: "IsPartOf", noSideEffect.}
+  ## not yet exported properly. 
+
+template compileTimeAssert(cond: expr) =
+  when not cond:
+    {.compile: "is false: " & astToStr(cond).}
+
+template `<|` (a, b: expr) =
+  compileTimeAssert isPartOf(a, b) == arYes
+
+template `!<|` (a, b: expr) =
+  compileTimeAssert isPartOf(a, b) == arNo
+
+template `?<|` (a, b: expr) =
+  compileTimeAssert isPartOf(a, b) == arMaybe
+
+type
+  TA {.inheritable.} = object
+  TC = object of TA
+    arr: array[0..3, int]
+    le, ri: ref TC
+    f: string
+    c: char
+    se: seq[TA]
+
+proc p(param1, param2: TC): TC =
+  var
+    local: TC
+    plocal: ptr TC
+    plocal2: ptr TA
+    
+  local.arr <| local
+  local.arr[0] <| local
+  local.arr[2] !<| local.arr[1]
+  
+  plocal2[] ?<| local
+
+  param1 ?<| param2
+  
+  local.arr[0] !<| param1
+  local.arr !<| param1
+  local.le[] ?<| param1
+  
+  param1 !<| local.arr[0]
+  param1 !<| local.arr
+  param1 ?<| local.le[]
+  
+  result !<| local
+  result <| result
+
+var
+  a, b: int
+  x: TC
+  
+a <| a
+a !<| b
+
+discard p(x, x)
+