Skip to content

[v2] fix(typing): Only convert integers of the same sign implicitly#1828

Open
teofr wants to merge 2 commits into
mainfrom
teofr/fix-int-convertibility
Open

[v2] fix(typing): Only convert integers of the same sign implicitly#1828
teofr wants to merge 2 commits into
mainfrom
teofr/fix-int-convertibility

Conversation

@teofr

@teofr teofr commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

@teofr teofr requested review from a team as code owners June 4, 2026 14:54
@teofr teofr requested a review from Copilot June 4, 2026 14:54
@changeset-bot

changeset-bot Bot commented Jun 4, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: ecbf2ea

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes Solidity v2 semantic typing by tightening integer implicit-conversion rules so that only integers with the same signedness (intN -> intM and uintN -> uintM) can convert implicitly. This aligns overload resolution (and other implicit-conversion-based typing) with Solidity’s expectation that signed/unsigned conversions require explicit casts.

Changes:

  • Restricts integer-to-integer implicit conversion to same-sign widening only.
  • Adds a regression test ensuring overload resolution rejects an unsigned argument for a signed parameter.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
crates/solidity-v2/outputs/cargo/semantic/src/types/registry.rs Simplifies and tightens integer implicit-conversion logic to require identical signedness and non-narrowing bit widths.
crates/solidity-v2/outputs/cargo/semantic/src/passes/tests/typing.rs Adds a test covering overload-resolution failure when only an unsigned-to-signed implicit conversion would have made a candidate match.

@ggiraldez ggiraldez left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change would only be valid for >= 0.8.1, unfortunately right at the edge of our version support cut. I'd extend the test to check both 0.8.0 and 0.8.1 as well.

from_bits < to_bits
}
}
) => from_signed == to_signed && from_bits <= to_bits,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs a version check. The change in behaviour occurs in 0.8.1. Worth noting that this will also affect validation for explicit casts.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I added the version throughout, and improved the tests

@teofr teofr force-pushed the teofr/fix-int-convertibility branch from 48cf39a to 0025f37 Compare June 5, 2026 11:10
@teofr teofr marked this pull request as draft June 5, 2026 11:13
@teofr

teofr commented Jun 5, 2026

Copy link
Copy Markdown
Contributor Author

@ggiraldez good catch, thank you!

I'll move this to draft since I think we need at least a moment's thought and maybe a chat on how to make our typing system versioned.

@ggiraldez

Copy link
Copy Markdown
Contributor

@ggiraldez good catch, thank you!

I'll move this to draft since I think we need at least a moment's thought and maybe a chat on how to make our typing system versioned.

In v1 we had a language_version field in TypeRegistry. It was removed because the version gate that it was used for was in 0.5.0, but we can easily reinstall that. I think it should be sufficient, no?

@teofr teofr force-pushed the teofr/fix-int-convertibility branch from 0025f37 to ececba0 Compare June 9, 2026 08:16
@teofr teofr force-pushed the teofr/fix-int-convertibility branch from ececba0 to ecbf2ea Compare June 9, 2026 08:22
@teofr teofr marked this pull request as ready for review June 9, 2026 08:22
@teofr

teofr commented Jun 9, 2026

Copy link
Copy Markdown
Contributor Author

In v1 we had a language_version field in TypeRegistry. It was removed because the version gate that it was used for was in 0.5.0, but we can easily reinstall that. I think it should be sufficient, no?

Fair point, it was simpler than I thought

@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

🐰 Bencher Report

Branchteofr/fix-int-convertibility
Testbedci

⚠️ WARNING: Truncated view!

The full continuous benchmarking report exceeds the maximum length allowed on this platform.

⚠️ WARNING: No Threshold found!

Without a Threshold, no Alerts will ever be generated.

🐰 View full continuous benchmarking report in Bencher

@ggiraldez ggiraldez left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants