Type-check primitives, let/var bindings, and blocks #48
Loading…
Reference in a new issue
No description provided.
Delete branch "us/2-type-check-primitives-let-var-blocks"
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 #2.
Summary
crates/twill-check/src/ty.rs:Ty(unsized primitive types),Scope(a stack of frames for let/var binding and lexical shadowing), and the
checker walk (
resolve_type_expr,check_let,check_expr,check_stmt).TypeExpr::Namedfor the five primitives (Int/Float/Bool/String/Unit); otherTypeExprvariants are recognized but not yetresolvable, reported as "not supported yet" rather than "unknown".
let/varbindings: annotation vs. inferred-value mismatches,redeclaration within the same block, and undefined-variable lookups.
Expr::BlockRust-style: the trailing expression's type (checkedwhile its own frame is still active, so it can see the block's own
bindings), or
Ty::Unitif there's no trailing expression.DiagnosticKindondiagnostic.rs'sDiagnosticgives every diagnosticstructured data (
Ty/Symbol/TypeExprpayloads) alongside a renderedmessage, instead of ad hoc strings.
#[salsa::tracked] check(db, file) -> Vec<Diagnostic>queryinto
queries.rs, alongside the existinglowerquery.docs/type-checker-design.md: records the design decisions made along theway (scope representation, diagnostic shape, query plumbing, etc.) per its
own living-doc convention.
Test plan
cargo test -p twill-check- 101 tests passing, including new unittests for Scope/resolve_type_expr/check_expr/check_let in ty.rs, and
end-to-end tests against check() in queries.rs (valid bindings,
mismatches, redeclaration, undefined variables, block
scoping/trailing-type behavior).