mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-19 14:00:35 +00:00
fixes #1838
This commit is contained in:
@@ -1317,18 +1317,20 @@ proc semYield(c: PContext, n: PNode): PNode =
|
||||
elif n.sons[0].kind != nkEmpty:
|
||||
n.sons[0] = semExprWithType(c, n.sons[0]) # check for type compatibility:
|
||||
var iterType = c.p.owner.typ
|
||||
var restype = iterType.sons[0]
|
||||
let restype = iterType.sons[0]
|
||||
if restype != nil:
|
||||
let adjustedRes = if c.p.owner.kind == skIterator: restype.base
|
||||
let adjustedRes = if restype.kind == tyIter: restype.base
|
||||
else: restype
|
||||
n.sons[0] = fitNode(c, adjustedRes, n.sons[0])
|
||||
if adjustedRes.kind != tyExpr:
|
||||
n.sons[0] = fitNode(c, adjustedRes, n.sons[0])
|
||||
if n.sons[0].typ == nil: internalError(n.info, "semYield")
|
||||
|
||||
if resultTypeIsInferrable(adjustedRes):
|
||||
let inferred = n.sons[0].typ
|
||||
if c.p.owner.kind == skIterator:
|
||||
iterType.sons[0].sons[0] = inferred
|
||||
if restype.kind == tyIter:
|
||||
restype.sons[0] = inferred
|
||||
else:
|
||||
debug inferred
|
||||
iterType.sons[0] = inferred
|
||||
|
||||
semYieldVarResult(c, n, adjustedRes)
|
||||
|
||||
@@ -939,7 +939,7 @@ proc semProcTypeNode(c: PContext, n, genericParams: PNode,
|
||||
r = semTypeNode(c, n.sons[0], nil)
|
||||
elif kind == skIterator:
|
||||
# XXX This is special magic we should likely get rid of
|
||||
r = newTypeS(tyAnything, c)
|
||||
r = newTypeS(tyExpr, c)
|
||||
|
||||
if r != nil:
|
||||
# turn explicit 'void' return type into 'nil' because the rest of the
|
||||
|
||||
@@ -6,13 +6,16 @@ discard """
|
||||
128
|
||||
192
|
||||
'''
|
||||
disabled: "true"
|
||||
"""
|
||||
|
||||
# This all relies on non-documented and questionable features.
|
||||
|
||||
iterator gaz(it: iterator{.inline.}): type(it) =
|
||||
for x in it:
|
||||
yield x*2
|
||||
|
||||
iterator baz(it: iterator{.inline.}) =
|
||||
iterator baz(it: iterator{.inline.}): auto =
|
||||
for x in gaz(it):
|
||||
yield x*2
|
||||
|
||||
|
||||
18
tests/iter/timplicit_auto.nim
Normal file
18
tests/iter/timplicit_auto.nim
Normal file
@@ -0,0 +1,18 @@
|
||||
# bug #1838
|
||||
|
||||
type State = enum Empty, Tree, Fire
|
||||
|
||||
const
|
||||
disp: array[State, string] = [" ", "\e[32m/\\\e[m", "\e[07;31m/\\\e[m"]
|
||||
|
||||
proc univ(x, y: int): State = Tree
|
||||
|
||||
var w, h = 30
|
||||
|
||||
iterator fields(a = (0,0), b = (h-1,w-1)) =
|
||||
for y in max(a[0], 0) .. min(b[0], h-1):
|
||||
for x in max(a[1], 0) .. min(b[1], w-1):
|
||||
yield (y,x)
|
||||
|
||||
for y,x in fields():
|
||||
stdout.write disp[univ(x, y)]
|
||||
Reference in New Issue
Block a user