-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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 + when: Cannot generate code #7378
Comments
Further investigation shows that the issue is actually with type
BaseUint* = SomeUnsignedInt or MpUintBase
MpUintBase*[BaseUint] = object
lo*, hi*: BaseUint
type
# works
Foo*[bits: static[int]] = (
when true:
MpUintBase[uint64]
)
type
# Cannot generate bits
Bar*[bits: static[int]] = (
when bits == 128: # Error points to the bits here
MpUintBase[uint64]
) |
This is not much of an issue with |
The snippet should work. In general, the |
The snippet should work but it is not working, here one more sample which are not working: type
Blake2Context*[bits: static[int]] = object
when bits == 384 or bits == 512:
b: array[128, byte]
h: array[8, uint64]
t: array[2, uint64]
c: int
elif bits == 224 or bits == 256:
b: array[64, byte]
h: array[8, uint32]
t: array[2, uint32]
c: int
blake2_224* = Blake2Context[224]
blake2_256* = Blake2Context[256]
blake2_384* = Blake2Context[384]
blake2_512* = Blake2Context[512]
proc init*[bits: static[int]](ctx: var Blake2Context[bits],
key: openarray[char]) {.inline.} =
discard
when isMainModule:
var c0: blake2_512
c0.init("abc")
var c1: blake2_224
c1.init("abc") |
The problem in @cheatfate snippet is harder to solve since |
This is an alternative approach due to the problem in #7230.
This might be solved by PR #7333.
The proc
fails_always
will trigger "Cannot generate code for: bits" as soon as it is uncommented.The proc
fails_if_called
triggers the same error if called.Edit: calling like this works:
The text was updated successfully, but these errors were encountered: