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

libp2p/crypto/minasn1.nim doesn't build on Nim version-2-2/devel #1194

Closed
tersec opened this issue Sep 17, 2024 · 4 comments · Fixed by #1195
Closed

libp2p/crypto/minasn1.nim doesn't build on Nim version-2-2/devel #1194

tersec opened this issue Sep 17, 2024 · 4 comments · Fixed by #1195
Assignees

Comments

@tersec
Copy link
Contributor

tersec commented Sep 17, 2024

nim-lang/Nim#24125

Not a terribly high-priority bug, but worth documenting here so no one else spends time hunting down the root cause of this.

The specific error one gets is:

nim-libp2p/libp2p/crypto/minasn1.nim(392, 36) Error: type mismatch
Expression: safeConvert[int](b)
  [1] b: byte

Expected one of (first mismatch at [position]):
[2] template safeConvert[T: SomeInteger; S: Ordinal](value: S): T
  missing generic parameter: S

and apparently was an accident it worked at all.

@diegomrsantos
Copy link
Contributor

Thanks for reporting it. Could you please explain why it was an accident it worked at all?

@tersec
Copy link
Contributor Author

tersec commented Sep 17, 2024

Thanks for reporting it. Could you please explain why it was an accident it worked at all?

Araq in nim-lang/Nim#24125 (comment) notes:

Partial explicit generic instantations are not in the language spec.

@diegomrsantos diegomrsantos self-assigned this Sep 17, 2024
@diegomrsantos
Copy link
Contributor

What would you recommend here? I'm not sure this proc is necessary.

@tersec
Copy link
Contributor Author

tersec commented Sep 18, 2024

template safeConvert*[T: SomeInteger](value: SomeOrdinal): T =
  ## Converts `value` to `T` iff `value` is guaranteed to be preserved.
  when int64(T.low) <= int64(typeof(value).low()) and
       uint64(T.high) >= uint64(typeof(value).high):
    T(value)
  else:
    {.error: "Source and target types have an incompatible range low..high".}

for example

github-merge-queue bot pushed a commit that referenced this issue Sep 19, 2024
- fixes #1194.
- fixes ambiguous `KeyError`
- removes an unnecessary type param for `newSeqWith`
- fixes tests for `safeConvert`

The main fixes relate to Nim 2.2 being more strict and not accepting
calls with a wrong number of type parameters.
@github-project-automation github-project-automation bot moved this from new to done in nim-libp2p Sep 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants