check map literals (bare, typed, keyed) #70

Merged
jacksonopp merged 1 commit from us57/map-literals into main 2026-09-17 21:12:33 +00:00
Owner

Closes #57.

Type-checks Expr::MapLiteral: key_type/value_type when present are the source of truth for every entry (MapKeyMismatch/MapValueMismatch otherwise), otherwise every key and every value must each agree with the first entry's inferred type — same shape as #56's array-literal checking, including the same starting_offset-based fix for Ty::error fallback symbols so two independently-broken entries can't collide into the same interned error type and silently dodge a mismatch diagnostic.

Same result-type gap as #56, for the same reason: no TyKind variant exists yet for a generic container instantiation, so this returns None rather than a real Map(K, V) — tracked in #69 (repointed #56/#57's stale Dependency notes there, since #6 never actually covered this). The dead if has_mismatch { None } else { None } branches are left in deliberately, as a marker for what #69 needs to fill in.

Test plan

  • cargo test --workspace (209 passing in twill-check; 8 new tests for check_map_literal covering bare/typed matching, empty, mismatched key, and mismatched value)
  • cargo clippy --workspace --all-targets --all-features
Closes #57. Type-checks `Expr::MapLiteral`: `key_type`/`value_type` when present are the source of truth for every entry (`MapKeyMismatch`/`MapValueMismatch` otherwise), otherwise every key and every value must each agree with the first entry's inferred type — same shape as #56's array-literal checking, including the same `starting_offset`-based fix for `Ty::error` fallback symbols so two independently-broken entries can't collide into the same interned error type and silently dodge a mismatch diagnostic. Same result-type gap as #56, for the same reason: no `TyKind` variant exists yet for a generic container instantiation, so this returns `None` rather than a real `Map(K, V)` — tracked in #69 (repointed #56/#57's stale `Dependency` notes there, since #6 never actually covered this). The dead `if has_mismatch { None } else { None }` branches are left in deliberately, as a marker for what #69 needs to fill in. ## Test plan - [x] `cargo test --workspace` (209 passing in `twill-check`; 8 new tests for `check_map_literal` covering bare/typed matching, empty, mismatched key, and mismatched value) - [x] `cargo clippy --workspace --all-targets --all-features`
check map literals
All checks were successful
CI / check (pull_request) Successful in 3m15s
6382b64ca0
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
jacksonopp/twill!70
No description provided.