Skip to content

Conversation

@Ph0enixKM
Copy link
Member

Basically we no longer need to provide an array type:

let arr = []
// ...
arr = foo() + [1] // At this point it infers the type to be `[Int]`

Copy link
Contributor

Copilot AI left a 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_type method 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.

@Ph0enixKM Ph0enixKM self-assigned this Dec 8, 2025
@Ph0enixKM Ph0enixKM merged commit c767a73 into staging Dec 10, 2025
14 checks passed
@Ph0enixKM Ph0enixKM deleted the 889-feature-dont-require-array-type-at-initialization branch December 10, 2025 13:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Don't require array type at initialization

3 participants