Type-check struct/enum definitions and struct literals #50
Loading…
Reference in a new issue
No description provided.
Delete branch "us4/type-check-struct-enum"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #4.
Summary
TyKind::Struct/TyKind::Enum, nominal (carry aname: Symbol), withenum variant payloads staying
Option<Ty>to distinguish a no-payloadvariant from a resolution failure.
check_exprgains aname_hint: Option<Symbol>parameter, populatedonly by
check_let, sostruct { ... }/enum { ... }declarations canbe named without needing their own syntax for it (per
let X = struct {...}).A
Nonehint reportsNamelessStruct/NamelessEnum.check_struct_literalchecksExpr::StructLiteralagainst its declaredstruct: name-based (not positional) field matching over the union of
literal/declared field names, catching unknown fields
(
StructFieldNotDefined), missing required fields (MissingStructType),and field type mismatches (
StructFieldMismatch) in one pass. A literalagainst an undeclared or non-struct name reports
NoStruct.Reserved(slot),match) isexplicitly out of scope — no
EnumLiteralHIR node exists; that'sExpr::Call/Expr::Matchchecking, later work.check_expr's match arms extracted into their own functions(
check_ident/check_block/check_fn/check_call/check_struct/check_enum/check_struct_literal) to keep it readable as moreconstructs are added.
docs/type-checker-design.mdgets a new## Issue #4sectiondocumenting these decisions.
Test plan
cargo test -p twill-check— 123 tests passing, including 6 newtests each for struct/enum declaration checking and struct-literal
checking (valid case, unknown field, missing field, mismatch,
not-a-struct, undefined name).