Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion docs/0.6.0-alpha/basic_syntax/data_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,18 @@ To create an array literal simply enclose a list of elements separated with a co
["apple", "banana", "orange"]
```

In a situation of empty array there is no value that can tell the compiler of what type it is. In this case we can simply use the type signature of it to represent an empty array.
### Array Type Resolution

Amber supports type inference for empty arrays. You can initialize an empty array using `[]` without specifying its type immediately. The type will be resolved later based on how the array is used.

```amber
// Initializes an empty array with unresolved type
let array = []
// The type is resolved to [Int] upon this assignment
array += [1]
```

In edge cases, where type inference is not possible or explicit typing is preferred, you can use the type signature to create an explicitly typed empty array.

```ab
// Example of a value that represents empty array of text
Expand Down
9 changes: 9 additions & 0 deletions docs/0.6.0-alpha/getting_started/whats_new.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ test "can multiply numbers" {

You can also name your tests for better readability and filter them by name or filename using CLI arguments. Read more in the [Testing Guide](testing).

# Array Type Resolution

Amber now supports type inference for empty arrays `[]`. You can initialize an empty array without specifying its type immediately. The type will be resolved later based on how the array is used, such as in assignments, binary operations, or function calls.

```ab
let arr = [] // Type is generic
arr += [1] // Resolved to [Int]
```

# Standard library improvements

> WARNING: Brief description of new changes TBD when releasing
Expand Down