Iterator fixes (#11234)
This commit is contained in:
parent
fb1c3a95a5
commit
6fc74cec55
8 changed files with 142 additions and 17 deletions
|
|
@ -1696,8 +1696,8 @@ proc semAsgn(c: PContext, n: PNode; mode=asgnNormal): PNode =
|
|||
proc semReturn(c: PContext, n: PNode): PNode =
|
||||
result = n
|
||||
checkSonsLen(n, 1, c.config)
|
||||
if c.p.owner.kind in {skConverter, skMethod, skProc, skFunc, skMacro} or (
|
||||
c.p.owner.kind == skIterator and c.p.owner.typ.callConv == ccClosure):
|
||||
if c.p.owner.kind in {skConverter, skMethod, skProc, skFunc, skMacro} or
|
||||
isClosureIterator(c.p.owner):
|
||||
if n.sons[0].kind != nkEmpty:
|
||||
# transform ``return expr`` to ``result = expr; return``
|
||||
if c.p.resultSym != nil:
|
||||
|
|
@ -1742,8 +1742,12 @@ proc semProcBody(c: PContext, n: PNode): PNode =
|
|||
c.p.resultSym.typ = errorType(c)
|
||||
c.p.owner.typ.sons[0] = nil
|
||||
else:
|
||||
localError(c.config, c.p.resultSym.info, errCannotInferReturnType)
|
||||
|
||||
localError(c.config, c.p.resultSym.info, errCannotInferReturnType %
|
||||
c.p.owner.name.s)
|
||||
if isInlineIterator(c.p.owner) and c.p.owner.typ.sons[0] != nil and
|
||||
c.p.owner.typ.sons[0].kind == tyUntyped:
|
||||
localError(c.config, c.p.owner.info, errCannotInferReturnType %
|
||||
c.p.owner.name.s)
|
||||
closeScope(c)
|
||||
|
||||
proc semYieldVarResult(c: PContext, n: PNode, restype: PType) =
|
||||
|
|
@ -1786,6 +1790,8 @@ proc semYield(c: PContext, n: PNode): PNode =
|
|||
if resultTypeIsInferrable(restype):
|
||||
let inferred = n.sons[0].typ
|
||||
iterType.sons[0] = inferred
|
||||
if c.p.resultSym != nil:
|
||||
c.p.resultSym.typ = inferred
|
||||
|
||||
semYieldVarResult(c, n, restype)
|
||||
else:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue