summary refs log tree commit diff stats
path: root/tests/overload
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2017-11-21 01:42:58 +0100
committerAraq <rumpf_a@web.de>2017-11-21 01:42:58 +0100
commit1bbab827c494d41cc87d6cb94524f5f23c54fe88 (patch)
tree4fbc478c72dbdc0dd5b84e6b1e581e7fa934d91e /tests/overload
parentfba5f5acd6ab1b0aaca79241f55f95b089fbad2c (diff)
parent2ad49836d95f5d825ba271d64cab1c312f3ccc31 (diff)
downloadNim-1bbab827c494d41cc87d6cb94524f5f23c54fe88.tar.gz
Merge branch 'devel' of github.com:nim-lang/Nim into devel
Diffstat (limited to 'tests/overload')
-rw-r--r--tests/overload/tstatic_with_converter.nim47
1 files changed, 47 insertions, 0 deletions
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