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

Unnecessary warning when implicitly casting small-enough literal integers to narrower types #606

Closed
Dentosal opened this issue Jan 9, 2022 · 3 comments
Assignees
Labels
compiler General compiler. Should eventually become more specific as the issue is triaged enhancement New feature or request

Comments

@Dentosal
Copy link
Member

Dentosal commented Jan 9, 2022

This shouldn't produce a warning, as the compiler should know that the literal is small enough.

Input

script;
fn main() {
  let a: u32 = 1;
  let b: u32 = a + 1;
}

Expected output

No warnings about casts

Actual output

warning
 --> fuel_project/src/main.sw:0:16
  |
...
2 |   let a: u32 = 1;
  |                - This cast, from integer type of width sixty four to integer type of width thirty two, will lose precision.
  |
warning
 --> fuel_project/src/main.sw:0:20
  |
...
3 |   let b: u32 = a + 1;
  |                    - This cast, from integer type of width sixty four to integer type of width thirty two, will lose precision.
  |
  Compiled script "Fuel example project" with 2 warnings.
@adlerjohn adlerjohn added the compiler General compiler. Should eventually become more specific as the issue is triaged label Jan 9, 2022
@adlerjohn adlerjohn moved this to Todo in Fuel Network Jan 9, 2022
@adlerjohn adlerjohn added the enhancement New feature or request label Jan 9, 2022
@mohammadfawaz
Copy link
Contributor

mohammadfawaz commented Feb 3, 2022

This should be fixed with #711

Edit. Not entirely - let b: u32 = a + 1; still gives a warning :(

@adlerjohn
Copy link
Contributor

This isn't fixed with arrays. See #2024

@anton-trunov
Copy link
Contributor

Fixed with #4829 I believe

@github-project-automation github-project-automation bot moved this from Todo to Done in Fuel Network Jul 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler General compiler. Should eventually become more specific as the issue is triaged enhancement New feature or request
Projects
Status: Done
Development

No branches or pull requests

4 participants