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

Remove shift type constraint #3607

Open
tarakby opened this issue Oct 9, 2024 · 2 comments
Open

Remove shift type constraint #3607

tarakby opened this issue Oct 9, 2024 · 2 comments

Comments

@tarakby
Copy link
Contributor

tarakby commented Oct 9, 2024

Issue to be solved

When using shift operations, the shift value currently has to match the result type.

  // works
  let shift256: UInt256 = 240
  let result: UInt256 = 1 << shift256

  // errors
  let shift8: UInt8 = 240
  result = 1 << shift8

Although there is no harm in the current way, this is a constraint that the parser could remove since the values of shift are much smaller than the result of the operation.

Suggested Solution

For a backward compatible change, we can remove the condition for the shift value to be of the same type of the result. The shift value can be a positive integer of any size.

@bluesign
Copy link
Contributor

bluesign commented Oct 9, 2024

The maximum value of shifts can be 255 since the largest type supported on Cadence is 256 bits.

Int can be bigger than 256 bits I guess.

@tarakby
Copy link
Contributor Author

tarakby commented Oct 9, 2024

oh you're right @bluesign, I didn't know Int also supports shifts.
I updated the description, the suggested solution should remain the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants