check array literals (bare, typed, sized) #68
Loading…
Reference in a new issue
No description provided.
Delete branch "us56/check-array-list-literals"
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 #56.
Type-checks
Expr::ArrayLiteral's three fields:element_typewhen present is the source of truth — every element must match it (ArrayTypeMismatchotherwise).[1, 2, 3]).sizewhen present must type-check toInt(InvalidArraySizeotherwise) and must match the literal's actual element count (ArraySizeMismatchotherwise) — checked independently from the element-type check, so a literal that's wrong on both counts reports both.As the issue's own "Dependency" note flags: there's no
TyKindvariant yet for a generic container instantiation, so the result type today is just the element type itself (Ty::int, etc.), not a realList(T)/sized-arrayTy. That's deferred along with #6'sTypeExpr::Genericresolution question, not solved here.Also includes a mechanical, unrelated-but-prerequisite refactor: every
check_*function's parameters were reordered to a consistent(db, scope, diagnostics, ...construct-specific)shape (previouslydiagnosticswas last with no particular reason) — done first so the newcheck_array_literal/check_array_size/array_members_contains_mismatchfunctions could follow the same convention from the start.Test plan
cargo test --workspace(201 + 229 + 27 passing; 10 new tests forcheck_array_literalcovering bare/typed/sized, matching/mismatched elements, empty arrays, wrong size, wrong size + wrong type together, and non-Intsize)cargo clippy --workspace --all-targets --all-features