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

Seems like an incorrect type inference... #15197

Closed
haoyang9804 opened this issue Jun 12, 2024 · 3 comments
Closed

Seems like an incorrect type inference... #15197

haoyang9804 opened this issue Jun 12, 2024 · 3 comments
Labels

Comments

@haoyang9804
Copy link
Contributor

haoyang9804 commented Jun 12, 2024

The following two statements are of the same functions:

int256 a = 22;
int256 a2 = true ? 22 : 23;

However, the second statement throws an error with message: Error: Type uint8 is not implicitly convertible to expected type int256. Seems that Solidity compiler misunderstood the type of 22 and cannot take it as a int256 literal as it did for the first statement.

This bug (or, this feature) is kind of confusing and causes a little inconvenience.

@PeterYang03110
Copy link

int256 a = 22;
int256 a2 = true ? int256(22) : int256(23);

@haoyang9804
Copy link
Contributor Author

int256 a = 22; int256 a2 = true ? int256(22) : int256(23);

Oh thx. I think it's a solution. But is it not a bug? I expect the type checker can infer the type of 22 and 23 in this scenario.

@mehtavishwa30
Copy link
Contributor

@haoyang9804 This behaviour is not a bug and is in fact the normal behaviour (see docs for reference). The type system does infer types in cases that are currently limited. However, we are aware of all the cases, the likes of above, that aren't covered well by the current type system and are working on bringing a better experience through the new type system in Solidity.

For now, I will be closing this issue given the above reasoning.

@mehtavishwa30 mehtavishwa30 closed this as not planned Won't fix, can't repro, duplicate, stale Jun 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants