Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing empty array to openarray parameter of template fails #2459

Open
Perelandric opened this issue Apr 4, 2015 · 3 comments
Open

Passing empty array to openarray parameter of template fails #2459

Perelandric opened this issue Apr 4, 2015 · 3 comments

Comments

@Perelandric
Copy link
Contributor

The last line of the following code example produces a compile-time error:

template test(a: openarray[int]) =
  for n in a:
    echo n

test([1,2,3]) # This works
test([])      # This fails

lib/system.nim(1695, 22) Error: invalid type: 'empty' in this context: 'iterator (array[0..-1, empty]): iter[empty]{.inline, gcsafe, locks: 0.}'

No such error when it's a proc, only a template.

Not sure if it's related to the behavior described here #1105 (comment) , which I tested and found to still exist, but thought I'd mention it anyway.

Nim Compiler Version 0.10.3 (2015-04-03) [Linux: amd64]

@Araq
Copy link
Member

Araq commented Oct 15, 2018

Still an issue.

@Araq Araq added the varargs label Oct 15, 2018
@narimiran narimiran removed the varargs label Feb 7, 2019
@kunitoki
Copy link

I stumbled into this as well in 1.4.8, pretty annoying one.

template test(a: openarray[int]) =
  for n in a:
    echo n

const x = []
test(x)

fails with:

test.nim(6, 5) template/generic instantiation of `test` from here
test.nim(3, 10) Error: type mismatch: got <empty>
but expected one of: 
proc echo(x: varargs[typed, `$`])
  first type mismatch at position: 1
  required type for x: varargs[typed]
  but expression 'n`gensym0' is of type: empty

expression: echo n`gensym0

@ringabout
Copy link
Member

Gives Error: cannot infer element type of items([]) on the devel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants