diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2018-06-12 11:50:40 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-12 11:50:40 +0200 |
commit | aaceec074456dcbbd6409faf07146a584b7439eb (patch) | |
tree | 015d1fdbb690ed97e7ba4843f7962a98ed148695 /tests/template | |
parent | 1c58f31a71d2fb8c8569a6ceb6fffc4778d1c7ab (diff) | |
parent | 44d82d94927424ce643aecba5231adb698bf3965 (diff) | |
download | Nim-aaceec074456dcbbd6409faf07146a584b7439eb.tar.gz |
Merge pull request #7981 from cooldome/Fix_-7980
Fixes 7980
Diffstat (limited to 'tests/template')
-rw-r--r-- | tests/template/tpattern_with_converter.nim | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/template/tpattern_with_converter.nim b/tests/template/tpattern_with_converter.nim new file mode 100644 index 000000000..e0632552b --- /dev/null +++ b/tests/template/tpattern_with_converter.nim @@ -0,0 +1,27 @@ +discard """ + output: 10.0 +""" + +type + MyFloat = object + val: float + +converter to_myfloat*(x: float): MyFloat {.inline.} = + MyFloat(val: x) + +proc `+`(x1, x2: MyFloat): MyFloat = + MyFloat(val: x1.val + x2.val) + +proc `*`(x1, x2: MyFloat): MyFloat = + MyFloat(val: x1.val * x2.val) + +template optMul{`*`(a, 2.0)}(a: MyFloat): MyFloat = + a + a + +func floatMyFloat(x: MyFloat): MyFloat = + result = x * 2.0 + +func floatDouble(x: float): float = + result = x * 2.0 + +echo floatDouble(5) \ No newline at end of file |