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

Problem with static[int] in return type #3309

Closed
Henry opened this issue Sep 8, 2015 · 3 comments
Closed

Problem with static[int] in return type #3309

Henry opened this issue Sep 8, 2015 · 3 comments
Assignees

Comments

@Henry
Copy link

Henry commented Sep 8, 2015

type
  OdArray*[As: static[int], T] = object
    l: int

proc initOdArray*[As: static[int], T](len: int): OdArray[As, T] =
  result.l = len

var test = initOdArray[10, int](100)

generates Error: type expected

See also forum discussion http://forum.nim-lang.org/t/1618

@Araq Araq added the Static[T] label Sep 14, 2015
@gmpreussner
Copy link
Contributor

This is still broken. Workaround:

type
  OdArray*[As: static[int], T] = object
    l: int

proc initOdArray*(As: static[int], T: typedesc, len: int): OdArray[As, T] =
  result.l = len

var test = initOdArray(10, int, 100)

@gmpreussner
Copy link
Contributor

The workaround does not work if the generic parameters need to be passed through to other types/procs/constructors:

type
  Foo[N: static[int], T] = object
    a: array[N, T]

  Bar[N: static[int], T] = object
    f: ref Foo[N, T]

proc initBar(N: static[int], T: typedesc): Bar[N, T] =
  result.f = Foo[N, T]()    ## Error: object constructor needs an object type

when isMainModule:
  var f = initBar(16, int)

@mratsim
Copy link
Collaborator

mratsim commented Mar 31, 2017

Seems like a duplicate of #1017

@zah zah self-assigned this Apr 1, 2017
zah added a commit that referenced this issue Jun 10, 2017
zah added a commit that referenced this issue Jun 19, 2017
@Araq Araq closed this as completed in 367d232 Jun 20, 2017
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

5 participants