summary refs log tree commit diff stats
path: root/tests
diff options
context:
space:
mode:
authorZahary Karadjov <zahary@gmail.com>2017-06-05 05:20:13 +0300
committerAndreas Rumpf <rumpf_a@web.de>2017-06-20 11:29:42 +0200
commitcd0256136839261b1c1b86c826d74cdbca5ddb67 (patch)
tree1a2043345025c2d849c680ace2707473b82bf04a /tests
parent30ccadfe4c7674cd8e58f6a8fe75055c4518dac3 (diff)
downloadNim-cd0256136839261b1c1b86c826d74cdbca5ddb67.tar.gz
introduce a pre-processing pass for the concept bodies
fixes #4982
fixes #3805

close #3414
Diffstat (limited to 'tests')
-rw-r--r--tests/concepts/t3414.nim22
-rw-r--r--tests/concepts/t4982.nim18
2 files changed, 40 insertions, 0 deletions
diff --git a/tests/concepts/t3414.nim b/tests/concepts/t3414.nim
new file mode 100644
index 000000000..d45973034
--- /dev/null
+++ b/tests/concepts/t3414.nim
@@ -0,0 +1,22 @@
+type
+  View[T] = concept v
+    v.empty is bool
+    v.front is T
+    popFront v
+
+proc find(view: View; target: View.T): View =
+  result = view
+
+  while not result.empty:
+    if view.front == target:
+      return
+
+    mixin popFront
+    popFront result
+
+proc popFront[T](s: var seq[T]) = discard
+proc empty[T](s: seq[T]): bool = false
+
+var s1 = @[1, 2, 3]
+let s2 = s1.find(10)
+
diff --git a/tests/concepts/t4982.nim b/tests/concepts/t4982.nim
new file mode 100644
index 000000000..9d82c83c9
--- /dev/null
+++ b/tests/concepts/t4982.nim
@@ -0,0 +1,18 @@
+discard """
+errormsg: "undeclared identifier: 'x'"
+line: 10
+"""
+
+import typetraits # without this import the program compiles (and echos false)
+
+type
+  SomeTestConcept = concept t
+    x.name is string # typo: t.name was intended (which would result in echo true)
+
+type
+  TestClass = ref object of RootObj
+    name: string
+
+var test = TestClass(name: "mytest")
+echo $(test is SomeTestConcept)
+