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

static[T] parameter cannot depend on generic type parameter #7209

Closed
andreaferretti opened this issue Feb 12, 2018 · 4 comments · Fixed by #22110
Closed

static[T] parameter cannot depend on generic type parameter #7209

andreaferretti opened this issue Feb 12, 2018 · 4 comments · Fixed by #22110

Comments

@andreaferretti
Copy link
Collaborator

andreaferretti commented Feb 12, 2018

The following

type Modulo[A; M: static[A]] = distinct A

proc `$`[A; M: static[A]](x: Modulo[A, M]): string =
  $(A(x)) & " mod " & $(M)

proc modulo[A](a: A, M: static[A]): Modulo[A, M] = Modulo[A, M](a %% M)

proc `+`[A; M: static[A]](x, y: Modulo[A, M]): Modulo[A, M] =
  (A(x) + A(y)).modulo(M)

when isMainModule:
  echo (3.modulo(7) + 5.modulo(7))

does not compile, while I would expect it to print 1 mod 7. The error is

Error: cannot instantiate Modulo
got: <type A, M>
but expected: <A, M>
@andreaferretti
Copy link
Collaborator Author

Any chance this could be tagged v1? I have been wanting to use this for some cryptography work since #3706 (even the non generic version used to fail) and it would be really nice to know fixing this is on the roadmap.

@Araq
Copy link
Member

Araq commented Aug 8, 2018

I don't know how hard this is to support and I wouldn't want this to block v1. We have a lot on our plate already. Sorry.

@Araq Araq added the Severe label Aug 8, 2018
@andreaferretti
Copy link
Collaborator Author

Fair enough :-)

@Araq
Copy link
Member

Araq commented Jul 6, 2019

I gave it another shot ... no progress so far...

metagn added a commit to metagn/Nim that referenced this issue Jun 16, 2023
Araq pushed a commit that referenced this issue Jun 16, 2023
* add test to close #7209

was fixed by #22029

* fix echo => doAssert
bung87 pushed a commit to bung87/Nim that referenced this issue Jul 29, 2023
* add test to close nim-lang#7209

was fixed by nim-lang#22029

* fix echo => doAssert
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants