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

Using generic static[int] as parameter in another static[...] parameter #4990

Closed
flyx opened this issue Nov 2, 2016 · 3 comments · Fixed by #24005
Closed

Using generic static[int] as parameter in another static[...] parameter #4990

flyx opened this issue Nov 2, 2016 · 3 comments · Fixed by #24005
Assignees
Labels
stale Staled PR/issues; remove the label after fixing them Static[T]

Comments

@flyx
Copy link
Contributor

flyx commented Nov 2, 2016

type Foo*[I: static[int], A: static[array[I, int]]] = object
  curIndex: int

proc next*[I: static[int], A: static[array[I, int]]](f: Foo[I, A]): string =
  discard

This yields:

test1.nim(1, 43) Error: cannot generate code for: I

Is this a bug or is it impossible to get working?

@Araq
Copy link
Member

Araq commented Nov 2, 2016

Seems just another static[T] bug.

@flyx
Copy link
Contributor Author

flyx commented Nov 3, 2016

Possibly the same bug, maybe a different one:

type
  Foo*[A: static[int], B: static[int], TokenType: enum, EofToken: static[TokenType]] = object
    curIndex: int

  MyEnum = enum
    meA, meB

  Bar = Foo[2, 3, MyEnum, meA]


proc next*[A: static[int], B: static[int], TokenType: enum,
           EofToken: static[TokenType]](f: Foo[A, B, TokenType, EofToken],
    a: static[(array[A, int], array[B, int])]): TokenType =
  TokenType(a[0][f.curIndex])

const
  a = [1, 2]
  b = [3, 4, 5]

template next*(bar: Bar): MyEnum =
  next(Foo[2, 3, MyEnum, meA](bar), (a, b))

let bar = Bar(curIndex: 0)

echo bar.next()

Yields:

test1.nim(23, 9) template/generic instantiation from here                                                                                                                             
test1.nim(11, 142) Error: cannot generate code for: A

The interesting thing is that this only happens if EofToken is present. If I remove that, the code will happily compile and run.

@Araq Araq added the Static[T] label Nov 3, 2016
@zah zah self-assigned this Mar 10, 2017
@stale
Copy link

stale bot commented Aug 4, 2020

This issue has been automatically marked as stale because it has not had recent activity. If you think it is still a valid issue, write a comment below; otherwise it will be closed. Thank you for your contributions.

@stale stale bot added the stale Staled PR/issues; remove the label after fixing them label Aug 4, 2020
metagn added a commit to metagn/Nim that referenced this issue Aug 25, 2024
metagn added a commit to metagn/Nim that referenced this issue Aug 25, 2024
@Araq Araq closed this as completed in 69ea133 Aug 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale Staled PR/issues; remove the label after fixing them Static[T]
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants