Skip to content

Commit

Permalink
reject proc fn(a: iterable)
Browse files Browse the repository at this point in the history
  • Loading branch information
timotheecour committed Apr 8, 2021
1 parent 47b42bc commit a7efee2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion compiler/typeallowed.nim
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ proc typeAllowedAux(marker: var IntSet, typ: PType, kind: TSymKind,
of tyUntyped, tyTyped:
if kind notin {skParam, skResult} or taNoUntyped in flags: result = t
of tyIterable:
if kind notin {skParam}: result = t
if kind notin {skParam} or taNoUntyped in flags: result = t
# tyIterable is only for templates and macros.
of tyStatic:
if kind notin {skParam}: result = t
of tyVoid:
Expand Down
13 changes: 13 additions & 0 deletions tests/types/titerable.nim
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ template bad1 =
template fn4(a: int, b: iterable[float, int]) =
discard

template bad2 =
proc fn4(a: iterable) = discard

template bad3 =
proc fn4(a: iterable[int]) = discard

template good4 =
template fn1(a: iterable) = discard
template fn2(a: iterable[int]) = discard

# iterators
iterator iota(n: int): auto =
for i in 0..<n: yield i
Expand Down Expand Up @@ -125,6 +135,9 @@ template main() =
doAssert toSeq2(@['x', 'y'].repeat(2)) == @[@['x', 'y'], @['x', 'y']]

reject bad1
reject bad2
reject bad3
accept good4

static: main()
main()

0 comments on commit a7efee2

Please sign in to comment.