diff options
author | Yuriy Glukhov <yutiy.glukhov@gmail.com> | 2016-04-05 22:44:10 +0300 |
---|---|---|
committer | Yuriy Glukhov <yutiy.glukhov@gmail.com> | 2016-04-07 21:24:43 +0300 |
commit | b6f5c12158a9ecfd602898970c2535ae88ce9d98 (patch) | |
tree | 45fb2ada87c186e1bab2e5114c7e3f913650751d | |
parent | 9a747828feeb3c25e5fe0caedc04a2af10ca3ce2 (diff) | |
download | Nim-b6f5c12158a9ecfd602898970c2535ae88ce9d98.tar.gz |
Fixed tr pattern matching for varargs
-rw-r--r-- | compiler/patterns.nim | 2 | ||||
-rw-r--r-- | compiler/types.nim | 11 | ||||
-rw-r--r-- | tests/trmacros/tpatterns.nim | 8 |
3 files changed, 19 insertions, 2 deletions
diff --git a/compiler/patterns.nim b/compiler/patterns.nim index 604d3521d..2336e44e7 100644 --- a/compiler/patterns.nim +++ b/compiler/patterns.nim @@ -129,7 +129,7 @@ proc matchNested(c: PPatternContext, p, n: PNode, rpn: bool): bool = result = bindOrCheck(c, p.sons[2].sym, arglist) proc matches(c: PPatternContext, p, n: PNode): bool = - # hidden conversions (?) + let n = skipHidden(n) if nfNoRewrite in n.flags: result = false elif isPatternParam(c, p): diff --git a/compiler/types.nim b/compiler/types.nim index 9aa991086..5d16ae42a 100644 --- a/compiler/types.nim +++ b/compiler/types.nim @@ -1448,6 +1448,17 @@ proc skipConv*(n: PNode): PNode = result = n.sons[1] else: discard +proc skipHidden*(n: PNode): PNode = + result = n + while true: + case result.kind + of nkHiddenStdConv, nkHiddenSubConv: + if result.sons[1].typ.classify == result.typ.classify: + result = result.sons[1] + of nkHiddenDeref, nkHiddenAddr: + result = result.sons[0] + else: break + proc skipConvTakeType*(n: PNode): PNode = result = n.skipConv result.typ = n.typ diff --git a/tests/trmacros/tpatterns.nim b/tests/trmacros/tpatterns.nim index 6bc8772e3..907973637 100644 --- a/tests/trmacros/tpatterns.nim +++ b/tests/trmacros/tpatterns.nim @@ -1,6 +1,7 @@ discard """ output: '''48 -hel''' +hel +lo''' """ template optZero{x+x}(x: int): int = x*3 @@ -15,3 +16,8 @@ s[0] = "hello" s[0] = substr(s[0], 0, 2) echo s[0] + +# Test varargs matching +proc someVarargProc(k: varargs[string]) = doAssert(false) # this should not get called +template someVarargProcSingleArg{someVarargProc([a])}(a: string) = echo a +someVarargProc("lo") |