-
Notifications
You must be signed in to change notification settings - Fork 102
Add array type inference #892
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add array type inference #892
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds array type inference functionality, allowing empty arrays [] to be used without explicit type annotations. The type is inferred from context such as assignments, function arguments, binary operations, and ternary expressions.
Key changes:
- Empty arrays are now parsed as generic
Type::Array(Box::new(Type::Generic))and have their types inferred from usage - Type inference works through variable assignments, function reference parameters, binary operations, comparisons, and ternary expressions
- The
update_var_typemethod enables updating variable types in metadata after inference
Reviewed changes
Copilot reviewed 37 out of 37 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
src/utils/metadata/parser.rs |
Adds update_var_type method to update variable types during type inference |
src/modules/types.rs |
Updates is_subset_of to support bidirectional generic-to-concrete array type relationships and adds corresponding tests |
src/modules/expression/literal/array.rs |
Changes empty array parsing to create generic arrays instead of returning an error |
src/modules/expression/ternop/ternary.rs |
Adds type inference logic for ternary expressions and stores resolved type in new kind field |
src/modules/variable/set.rs |
Implements type inference for both array element assignment and full array reassignment |
src/modules/shorthand/add.rs |
Adds type inference when using += operator with generic arrays |
src/modules/function/invocation.rs |
Infers array types from function reference parameters when passing generic arrays |
src/modules/expression/binop/mod.rs |
Adds array type inference logic to typecheck_equality method and updates signatures to &mut |
src/modules/expression/binop/*.rs |
Updates all binary operators to use mutable references for type inference support |
src/tests/validity/*.ab |
Comprehensive test cases validating array type inference in various scenarios |
src/tests/erroring/*.ab |
Test cases ensuring type mismatches are properly caught after inference |
src/tests/validity/modulo_num.ab |
Test for modulo operation with numeric types (appears related to operator refactoring) |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Basically we no longer need to provide an array type: