Merge pull request #4050 from yglukhov/tr-varargs
Fixed tr pattern matching for varargs
This commit is contained in:
commit
1d5c28fc14
3 changed files with 20 additions and 2 deletions
|
|
@ -129,7 +129,7 @@ proc matchNested(c: PPatternContext, p, n: PNode, rpn: bool): bool =
|
||||||
result = bindOrCheck(c, p.sons[2].sym, arglist)
|
result = bindOrCheck(c, p.sons[2].sym, arglist)
|
||||||
|
|
||||||
proc matches(c: PPatternContext, p, n: PNode): bool =
|
proc matches(c: PPatternContext, p, n: PNode): bool =
|
||||||
# hidden conversions (?)
|
let n = skipHidden(n)
|
||||||
if nfNoRewrite in n.flags:
|
if nfNoRewrite in n.flags:
|
||||||
result = false
|
result = false
|
||||||
elif isPatternParam(c, p):
|
elif isPatternParam(c, p):
|
||||||
|
|
|
||||||
|
|
@ -1448,6 +1448,18 @@ proc skipConv*(n: PNode): PNode =
|
||||||
result = n.sons[1]
|
result = n.sons[1]
|
||||||
else: discard
|
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]
|
||||||
|
else: break
|
||||||
|
of nkHiddenDeref, nkHiddenAddr:
|
||||||
|
result = result.sons[0]
|
||||||
|
else: break
|
||||||
|
|
||||||
proc skipConvTakeType*(n: PNode): PNode =
|
proc skipConvTakeType*(n: PNode): PNode =
|
||||||
result = n.skipConv
|
result = n.skipConv
|
||||||
result.typ = n.typ
|
result.typ = n.typ
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
discard """
|
discard """
|
||||||
output: '''48
|
output: '''48
|
||||||
hel'''
|
hel
|
||||||
|
lo'''
|
||||||
"""
|
"""
|
||||||
|
|
||||||
template optZero{x+x}(x: int): int = x*3
|
template optZero{x+x}(x: int): int = x*3
|
||||||
|
|
@ -15,3 +16,8 @@ s[0] = "hello"
|
||||||
s[0] = substr(s[0], 0, 2)
|
s[0] = substr(s[0], 0, 2)
|
||||||
|
|
||||||
echo s[0]
|
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")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue