summary refs log tree commit diff stats
path: root/tests/overload/tprefer_tygenericinst.nim
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2015-03-09 15:02:28 +0100
committerAraq <rumpf_a@web.de>2015-03-10 12:32:46 +0100
commit1efb5174f26caeebafe1b5ea9487690c5ffe1adb (patch)
tree90b292c6f6b2c45b24b26b9202fc9e13d0035298 /tests/overload/tprefer_tygenericinst.nim
parent3ea3aa633d92e9a9c3f4668727c194cfae3ce7c4 (diff)
downloadNim-1efb5174f26caeebafe1b5ea9487690c5ffe1adb.tar.gz
fixes #2220; #2219; breaks #2022; for #2022 callsite needs to be used
Diffstat (limited to 'tests/overload/tprefer_tygenericinst.nim')
-rw-r--r--tests/overload/tprefer_tygenericinst.nim43
1 files changed, 34 insertions, 9 deletions
diff --git a/tests/overload/tprefer_tygenericinst.nim b/tests/overload/tprefer_tygenericinst.nim
index 2700bed5e..9787af06b 100644
--- a/tests/overload/tprefer_tygenericinst.nim
+++ b/tests/overload/tprefer_tygenericinst.nim
@@ -1,17 +1,42 @@
 discard """
-  output: "Version 2 was called."
-  disabled: true
+  output: '''Version 2 was called.
+This has the highest precedence.
+This has the second-highest precedence.
+This has the lowest precedence.'''
 """
 
 # bug #2220
+when true:
+  type A[T] = object
+  type B = A[int]
 
-type A[T] = object
-type B = A[int]
+  proc q[X](x: X) =
+    echo "Version 1 was called."
 
-proc p[X](x: X) =
-  echo "Version 1 was called."
+  proc q(x: B) =
+    echo "Version 2 was called."
 
-proc p(x: B) =
-  echo "Version 2 was called."
+  q(B()) # This call reported as ambiguous.
 
-p(B()) # This call reported as ambiguous.
+# bug #2219
+template testPred(a: expr) =
+  block:
+    type A = object of RootObj
+    type B = object of A
+    type SomeA = A|A # A hack to make "A" a typeclass.
+
+    when a >= 3:
+      proc p[X](x: X) =
+        echo "This has the highest precedence."
+    when a >= 2:
+      proc p[X: A](x: X) =
+        echo "This has the second-highest precedence."
+    when a >= 1:
+      proc p[X: SomeA](x: X) =
+        echo "This has the lowest precedence."
+
+    p(B())
+
+testPred(3)
+testPred(2)
+testPred(1)