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

toConstantSized does not work as expected #3445

Closed
turbolent opened this issue Jul 2, 2024 · 0 comments · Fixed by #3446
Closed

toConstantSized does not work as expected #3445

turbolent opened this issue Jul 2, 2024 · 0 comments · Fixed by #3446
Assignees
Labels
Bug Something isn't working Feedback

Comments

@turbolent
Copy link
Member

Current Behavior

Reported by @sisyphusSmiling on Discord https://discord.com/channels/613813861610684416/1108479699732152503/1257730833352233131:

I ran into a really strange behaviour with the toConstantSized function. Take a look at this script:

access(all) fun main(): [UInt8;20] {
    let hexStr = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" // 20-byte hex string
    let res = hexStr.decodeHex().toConstantSized<[UInt8;20]>() ?? panic("toConstantSized failed")
    return res
}

This panics every time, even though the cast should work. But, if I rewrite it like this:

access(all) fun main(): [UInt8;20] {
    let hexStr = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
    let res = hexStr.decodeHex().toConstantSized<[UInt8;20]>()
    let res2 = res ?? panic("toConstantSized failed")
    return res2
}

Expected Behavior

Both scripts succeed

Steps To Reproduce

Use flow-c1 cadence script.cdc for the first script and it panics

Environment

- Cadence version: Latest preview release (v1.0.0-preview.35)
- Network: N/A
@turbolent turbolent added Bug Something isn't working Feedback labels Jul 2, 2024
@turbolent turbolent self-assigned this Jul 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Feedback
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant