fixes #7524
This commit is contained in:
parent
65593e76f4
commit
825e08b046
3 changed files with 23 additions and 9 deletions
|
|
@ -115,20 +115,19 @@ proc compileConstraints(p: PNode, result: var TPatternCode; conf: ConfigRef) =
|
||||||
else:
|
else:
|
||||||
patternError(p, conf)
|
patternError(p, conf)
|
||||||
|
|
||||||
proc semNodeKindConstraints*(p: PNode; conf: ConfigRef): PNode =
|
proc semNodeKindConstraints*(n: PNode; conf: ConfigRef; start: Natural): PNode =
|
||||||
## does semantic checking for a node kind pattern and compiles it into an
|
## does semantic checking for a node kind pattern and compiles it into an
|
||||||
## efficient internal format.
|
## efficient internal format.
|
||||||
assert p.kind == nkCurlyExpr
|
result = newNodeI(nkStrLit, n.info)
|
||||||
result = newNodeI(nkStrLit, p.info)
|
|
||||||
result.strVal = newStringOfCap(10)
|
result.strVal = newStringOfCap(10)
|
||||||
result.strVal.add(chr(aqNone.ord))
|
result.strVal.add(chr(aqNone.ord))
|
||||||
if p.len >= 2:
|
if n.len >= 2:
|
||||||
for i in 1..<p.len:
|
for i in start..<n.len:
|
||||||
compileConstraints(p.sons[i], result.strVal, conf)
|
compileConstraints(n[i], result.strVal, conf)
|
||||||
if result.strVal.len > MaxStackSize-1:
|
if result.strVal.len > MaxStackSize-1:
|
||||||
internalError(conf, p.info, "parameter pattern too complex")
|
internalError(conf, n.info, "parameter pattern too complex")
|
||||||
else:
|
else:
|
||||||
patternError(p, conf)
|
patternError(n, conf)
|
||||||
result.strVal.add(ppEof)
|
result.strVal.add(ppEof)
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
|
||||||
|
|
@ -1028,7 +1028,12 @@ proc liftParamType(c: PContext, procKind: TSymKind, genericParams: PNode,
|
||||||
proc semParamType(c: PContext, n: PNode, constraint: var PNode): PType =
|
proc semParamType(c: PContext, n: PNode, constraint: var PNode): PType =
|
||||||
if n.kind == nkCurlyExpr:
|
if n.kind == nkCurlyExpr:
|
||||||
result = semTypeNode(c, n.sons[0], nil)
|
result = semTypeNode(c, n.sons[0], nil)
|
||||||
constraint = semNodeKindConstraints(n, c.config)
|
constraint = semNodeKindConstraints(n, c.config, 1)
|
||||||
|
elif n.kind == nkCall and
|
||||||
|
n[0].kind in {nkIdent, nkSym, nkOpenSymChoice, nkClosedSymChoice} and
|
||||||
|
considerQuotedIdent(c, n[0]).s == "{}":
|
||||||
|
result = semTypeNode(c, n[1], nil)
|
||||||
|
constraint = semNodeKindConstraints(n, c.config, 2)
|
||||||
else:
|
else:
|
||||||
result = semTypeNode(c, n, nil)
|
result = semTypeNode(c, n, nil)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -77,3 +77,13 @@ block tstar:
|
||||||
|
|
||||||
# check that it's been optimized properly:
|
# check that it's been optimized properly:
|
||||||
doAssert calls == 1
|
doAssert calls == 1
|
||||||
|
|
||||||
|
# bug #7524
|
||||||
|
template in_to_out(typIn, typOut: typedesc) =
|
||||||
|
proc to_out(x: typIn{lit}): typOut = result = ord(x)
|
||||||
|
|
||||||
|
# Generating the proc via template doesn't work
|
||||||
|
in_to_out(char, int)
|
||||||
|
|
||||||
|
# This works
|
||||||
|
proc to_out2(x: char{lit}): int = result = ord(x)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue