Skip to content

Commit fcda910

Browse files
authored
feat: add array type inference (#135)
1 parent 7db803f commit fcda910

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

docs/0.6.0-alpha/basic_syntax/data_types.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,18 @@ To create an array literal simply enclose a list of elements separated with a co
9898
["apple", "banana", "orange"]
9999
```
100100

101-
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.
101+
### Array Type Resolution
102+
103+
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.
104+
105+
```amber
106+
// Initializes an empty array with unresolved type
107+
let array = []
108+
// The type is resolved to [Int] upon this assignment
109+
array += [1]
110+
```
111+
112+
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.
102113

103114
```ab
104115
// Example of a value that represents empty array of text

docs/0.6.0-alpha/getting_started/whats_new.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@ test "can multiply numbers" {
2727

2828
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).
2929

30+
# Array Type Resolution
31+
32+
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.
33+
34+
```ab
35+
let arr = [] // Type is generic
36+
arr += [1] // Resolved to [Int]
37+
```
38+
3039
# Standard library improvements
3140

3241
> WARNING: Brief description of new changes TBD when releasing

0 commit comments

Comments
 (0)