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

Span slicing inside dynamic type procs fails to compile #43

Closed
edubart opened this issue Sep 16, 2017 · 4 comments
Closed

Span slicing inside dynamic type procs fails to compile #43

edubart opened this issue Sep 16, 2017 · 4 comments

Comments

@edubart
Copy link
Contributor

edubart commented Sep 16, 2017

Minor test case:

import arraymancer

proc boo[T](): T =
  var a = zeros([2,2], int)
  echo a[1,_]

discard boo[int]()

When compiling the following error is shown:

test.nim(4, 12) Error: undeclared identifier: '_'

Removing dynamic type [T] from the proc the code works fine.

@mratsim
Copy link
Owner

mratsim commented Sep 16, 2017

I've reproduced it and reported it to Nim upstream.

It seems like for generic procs, there is an identifier resolution happening before the macros kick-in and replace "_".

I may have a workaround by exporting a dummy "_" but I don't want to pollute namespace with that symbol. And it's used in tuple pattern-matching as well and maybe by other libs.

@mratsim
Copy link
Owner

mratsim commented Sep 19, 2017

You can workaround that issue by using mixin _ from module macros in the procs that uses "_"

@edubart
Copy link
Contributor Author

edubart commented Sep 19, 2017

This workaround does not work with more complex silicing, like x[_, _, ^1..0|-1]

@mratsim
Copy link
Owner

mratsim commented Sep 20, 2017

Not sure which identifier poses the issue here, with seq I can "solve" it by adding everything as mixin :/

proc foo4[T](): CustomSeq[T] =
  result.data.newSeq(10)
  # weird fancy corner case that feels special and wants special treatment
  mixin _,`|-`
  # why?
  echo result[_, _, ^1..0|-1]

Case is closed upstream, but I really think generics have an issue as detailed by Krux

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

2 participants