Skip to content

[v2] fix common and mobile type mechanism#1792

Merged
teofr merged 4 commits into
mainfrom
teofr/fix-mobile-types
May 27, 2026
Merged

[v2] fix common and mobile type mechanism#1792
teofr merged 4 commits into
mainfrom
teofr/fix-mobile-types

Conversation

@teofr

@teofr teofr commented May 22, 2026

Copy link
Copy Markdown
Contributor

Various fixes around mobile and common type calculation:

  • mobile_type is now more general, checking if a type is array compatible is done later
  • the cases of conditional expressions are made mobile before looking for the common type, this matches solc and disallows certain cases like true ? bytes32(0) : 0
  • Refactor around typing tests to consolidate the pipeline, I think we still need snapshot testing infrastructure for valid typing scenarios. Also added an extra kind of test, try_type_of_function_body_expression
  • Added a bunch of tests around type unification
  • Refactor around common_mobile_type

@teofr teofr requested a review from Copilot May 22, 2026 14:18
@changeset-bot

changeset-bot Bot commented May 22, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 918189d

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 refines Solidity v2 typing/unification to better match solc semantics by separating “common type via implicit convertibility” from “mobile-type promotion,” and by applying those rules differently for array literals vs conditional expressions.

Changes:

  • Add TypeRegistry::common_type (implicit-convertibility-only) and TypeRegistry::mobile_type_id, and rework common_mobile_type to delay mobile-typing for non-first array elements.
  • Update conditional-expression typing to mobile-type both branches before unifying (matching solc’s stricter behavior vs array literals).
  • Add Type::can_be_array_element and enforce it for array literals; expand and refactor typing tests with a reusable semantic pipeline setup.

Reviewed changes

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

Show a summary per file
File Description
crates/solidity-v2/outputs/cargo/semantic/src/types/registry.rs Introduces common_type/mobile_type_id and adjusts array-literal unification to preserve literal-specific conversions where appropriate.
crates/solidity-v2/outputs/cargo/semantic/src/types/mod.rs Updates mobile_type behavior and adds can_be_array_element for array-literal validity checks.
crates/solidity-v2/outputs/cargo/semantic/src/passes/p4_resolve_references/visitor.rs Changes conditional-expression typing to mobile-type both branches before unifying.
crates/solidity-v2/outputs/cargo/semantic/src/passes/p4_resolve_references/typing.rs Enforces can_be_array_element when typing array literals.
crates/solidity-v2/outputs/cargo/semantic/src/passes/tests/typing.rs Refactors test setup and adds coverage for array-vs-conditional unification differences and mapping/array-element constraints.

@teofr teofr changed the title [v2] fix common type, delay mobile [v2] fix common and mobile type mechanism May 22, 2026
@teofr teofr marked this pull request as ready for review May 22, 2026 14:30
@teofr teofr requested review from a team as code owners May 22, 2026 14:30

@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.

I left some suggestions. I think the semantic of type unification behind the two cases (conditional expressions and array literals) are different enough that it makes sense to separate the code.

The tests refactor may be out of scope for this PR, but since you're already making heavy modifications here, it may make sense to do it altogether. Happy to push to a different PR if you prefer.

Comment thread crates/solidity-v2/outputs/cargo/semantic/src/types/registry.rs Outdated
Comment thread crates/solidity-v2/outputs/cargo/semantic/src/types/registry.rs Outdated
Comment thread crates/solidity-v2/outputs/cargo/semantic/src/types/registry.rs Outdated
Comment thread crates/solidity-v2/outputs/cargo/semantic/src/types/mod.rs Outdated
Comment thread crates/solidity-v2/outputs/cargo/semantic/src/types/registry.rs
Comment thread crates/solidity-v2/outputs/cargo/semantic/src/passes/tests/typing.rs Outdated
Comment thread crates/solidity-v2/outputs/cargo/semantic/src/passes/tests/typing.rs Outdated
@ggiraldez

Copy link
Copy Markdown
Contributor

Also, after working on #1793 to expose mobile_type() to solx, I think it makes sense to restrict the implementation to LiteralKind. compute_mobile_type() would still be necessary to recurse into tuples of literals.

@teofr teofr force-pushed the teofr/fix-mobile-types branch 2 times, most recently from 34f549c to 7e679a2 Compare May 26, 2026 12:40
@teofr teofr force-pushed the teofr/fix-mobile-types branch from 7e679a2 to 9673de4 Compare May 26, 2026 12:52

@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.

Looks great, thank you!

Comment thread crates/solidity-v2/outputs/cargo/semantic/src/types/registry.rs Outdated
Comment thread crates/solidity-v2/outputs/cargo/semantic/src/passes/tests/typing.rs Outdated
Co-authored-by: Gustavo Giráldez <ggiraldez@manas.tech>
@teofr teofr enabled auto-merge May 26, 2026 18:50
…ing.rs

Co-authored-by: Gustavo Giráldez <ggiraldez@manas.tech>
@teofr teofr force-pushed the teofr/fix-mobile-types branch from 9b2d81b to 918189d Compare May 27, 2026 10:10
@teofr teofr added this pull request to the merge queue May 27, 2026
Merged via the queue into main with commit 1f37db4 May 27, 2026
16 checks passed
@teofr teofr deleted the teofr/fix-mobile-types branch May 27, 2026 10:43
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