Skip to content

feat(units): track struct field units through let bindings, call results and nested access - #541

Merged
AkiraTamai merged 2 commits into
developfrom
devin/1788349177-units-struct-fields
Sep 2, 2026
Merged

feat(units): track struct field units through let bindings, call results and nested access#541
AkiraTamai merged 2 commits into
developfrom
devin/1788349177-units-struct-fields

Conversation

@AkiraTamai

Copy link
Copy Markdown
Collaborator

Summary

Follow-up to #539 (review finding). The unit checker resolved x.field only when x was a parameter or result; let p = Price {..}; p.jpy + usd, mk_price(u, j).jpy + usd and q.price.jpy + usd silently passed as unitless.

support/units.rs now propagates a small type descriptor instead of a bare unit:

struct Ty { unit: Option<String>, struct_name: Option<String> }
vars: HashMap<String, Ty>          // was HashMap<String, String>
fn infer(&self, expr) -> MumeiResult<Ty>   // was -> MumeiResult<Unit>

struct_name is seeded from param/-> T types, Struct { .. } literals and callee return types, flows through let, if/match branches, and FieldAccess looks the field up on the inferred target type (so nesting works). Unit compatibility rules are unchanged; arrays remain unitless (documented in docs/LANGUAGE.md).

Fixtures: tests/test_units_struct_ok.mm (positive) and test_units_struct_mismatch_{let,call,nested}.mm (each rejected with Unit mismatch ... 'JPY' with 'USD'), wired in tests/test_units.rs.

Link to Devin session: https://app.devin.ai/sessions/2eef5afcd69d4e0ab19ada3b22d5cf7e
Open in Devin Desktop: https://app.devin.ai/desktop/session/2eef5afcd69d4e0ab19ada3b22d5cf7e?variant=devin
Requested by: @AkiraTamai

…lts and nested access

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

@AkiraTamai
AkiraTamai marked this pull request as ready for review September 2, 2026 13:05

@devin-ai-integration devin-ai-integration Bot 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.

Devin Review found 3 potential issues.

Devin Review

Comment thread mumei-core/src/verification/support/units.rs Outdated
Comment thread mumei-core/src/verification/support/units.rs
Comment thread mumei-core/src/verification/support/units.rs
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@AkiraTamai
AkiraTamai merged commit 618bc42 into develop Sep 2, 2026
3 checks passed
@AkiraTamai
AkiraTamai deleted the devin/1788349177-units-struct-fields branch September 2, 2026 13:24
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.

1 participant