summary refs log tree commit diff stats
path: root/tests/overload
diff options
context:
space:
mode:
Diffstat (limited to 'tests/overload')
-rw-r--r--tests/overload/tprefer_tygenericinst.nim36
-rw-r--r--tests/overload/tstatic_with_converter.nim47
2 files changed, 78 insertions, 5 deletions
diff --git a/tests/overload/tprefer_tygenericinst.nim b/tests/overload/tprefer_tygenericinst.nim
index 56541c7e8..ab461a0f4 100644
--- a/tests/overload/tprefer_tygenericinst.nim
+++ b/tests/overload/tprefer_tygenericinst.nim
@@ -2,7 +2,11 @@ discard """
   output: '''Version 2 was called.
 This has the highest precedence.
 This has the second-highest precedence.
-This has the lowest precedence.'''
+This has the lowest precedence.
+baseobj ==
+true
+even better! ==
+true'''
 """
 
 # bug #2220
@@ -26,13 +30,13 @@ template testPred(a: untyped) =
     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 highest precedence."
+    when a == 2:
+      proc p[X: SomeA](x: X) =
         echo "This has the second-highest precedence."
     when a >= 1:
-      proc p[X: SomeA](x: X) =
+      proc p[X](x: X) =
         echo "This has the lowest precedence."
 
     p(B())
@@ -40,3 +44,25 @@ template testPred(a: untyped) =
 testPred(3)
 testPred(2)
 testPred(1)
+
+# bug #6526
+type
+  BaseObj = ref object of RootObj
+  DerivedObj = ref object of BaseObj
+  OtherDerivate = ref object of BaseObj
+
+proc `==`*[T1, T2: BaseObj](a: T1, b: T2): bool =
+  echo "baseobj =="
+  return true
+
+let a = DerivedObj()
+let b = DerivedObj()
+echo a == b
+
+proc `==`*[T1, T2: OtherDerivate](a: T1, b: T2): bool =
+  echo "even better! =="
+  return true
+
+let a2 = OtherDerivate()
+let b2 = OtherDerivate()
+echo a2 == b2
diff --git a/tests/overload/tstatic_with_converter.nim b/tests/overload/tstatic_with_converter.nim
new file mode 100644
index 000000000..2871744eb
--- /dev/null
+++ b/tests/overload/tstatic_with_converter.nim
@@ -0,0 +1,47 @@
+discard """
+output: '''
+9.0'''
+"""
+
+### bug #6773
+
+{.emit: """ /*INCLUDESECTION*/
+typedef double cimported;
+ 
+cimported set1_imported(double x) {
+  return x;
+}
+ 
+"""}
+ 
+type vfloat{.importc: "cimported".} = object
+ 
+proc set1(a: float): vfloat {.importc: "set1_imported".}
+ 
+converter scalar_to_vector(x: float): vfloat =
+  set1(x)
+ 
+proc sqrt(x: vfloat): vfloat =
+  x
+ 
+proc pow(x, y: vfloat): vfloat =
+  y
+ 
+proc `^`(x: vfloat, exp: static[int]): vfloat =
+  when exp == 0:
+    1.0
+  else:
+    x
+ 
+proc `^`(x: vfloat, exp: static[float]): vfloat =
+  when exp == 0.5:
+    sqrt(x)
+  else:
+   pow(x, exp)
+ 
+proc `$`(x: vfloat): string =
+  let y = cast[ptr float](unsafeAddr x)
+  echo y[]
+ 
+let x = set1(9.0)
+echo x^0.5