check .field access on structs #65

Merged
jacksonopp merged 2 commits from us55/field-access-on-structs into main 2026-09-16 19:17:39 +00:00
Owner

Closes #55.

Type-checks Expr::Field: base must resolve to a TyKind::Struct, and name must be one of its declared fields; the access resolves to that field's declared type. Reports TypeNotAStruct(Ty) when the base isn't a struct, and StructFieldNotDefined { name, field } when it is but the field doesn't exist — reusing the diagnostic already used by check_struct_literal.

Filed #64 as a follow-up: Expr::Field's name has no span (it's a bare Ident/Symbol), so both diagnostics currently point at base's span rather than the field name itself.

Test plan

  • cargo test -p twill-check (new unit tests for a valid field access, an unknown field, a non-struct base, and an undefined base var not double-reporting)
Closes #55. Type-checks `Expr::Field`: `base` must resolve to a `TyKind::Struct`, and `name` must be one of its declared fields; the access resolves to that field's declared type. Reports `TypeNotAStruct(Ty)` when the base isn't a struct, and `StructFieldNotDefined { name, field }` when it is but the field doesn't exist — reusing the diagnostic already used by `check_struct_literal`. Filed #64 as a follow-up: `Expr::Field`'s `name` has no span (it's a bare `Ident`/`Symbol`), so both diagnostics currently point at `base`'s span rather than the field name itself. ## Test plan - [x] `cargo test -p twill-check` (new unit tests for a valid field access, an unknown field, a non-struct base, and an undefined base var not double-reporting)
add tests for check field
All checks were successful
CI / check (pull_request) Successful in 3m8s
47003973d5
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!65
No description provided.