fixes 7980
This commit is contained in:
parent
bf394ed1a1
commit
e03b3bdde7
2 changed files with 56 additions and 21 deletions
|
|
@ -36,6 +36,14 @@ proc applyPatterns(c: PContext, n: PNode): PNode =
|
||||||
# we apply the last pattern first, so that pattern overriding is possible;
|
# we apply the last pattern first, so that pattern overriding is possible;
|
||||||
# however the resulting AST would better not trigger the old rule then
|
# however the resulting AST would better not trigger the old rule then
|
||||||
# anymore ;-)
|
# anymore ;-)
|
||||||
|
if c.patterns.len > 0:
|
||||||
|
|
||||||
|
# temporary disable converters
|
||||||
|
var ctx_converters: TSymSeq
|
||||||
|
shallowCopy(ctx_converters, c.converters)
|
||||||
|
c.converters = @[]
|
||||||
|
defer: shallowCopy(c.converters, ctx_converters)
|
||||||
|
|
||||||
for i in countdown(c.patterns.len-1, 0):
|
for i in countdown(c.patterns.len-1, 0):
|
||||||
let pattern = c.patterns[i]
|
let pattern = c.patterns[i]
|
||||||
if not isNil(pattern):
|
if not isNil(pattern):
|
||||||
|
|
|
||||||
27
tests/template/tpattern_with_converter.nim
Normal file
27
tests/template/tpattern_with_converter.nim
Normal file
|
|
@ -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)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue