mirror of
https://github.com/Ed94/Odin.git
synced 2026-06-23 06:05:00 -07:00
Add ranged_fields_for_array_compound_literals
This commit is contained in:
+37
-7
@@ -1194,13 +1194,43 @@ ranged_fields_for_array_compound_literals :: proc() {
|
||||
foo := [?]int{1, 4, 9, 16};
|
||||
fmt.println(foo);
|
||||
}
|
||||
i := 2;
|
||||
foo := [?]int {
|
||||
0 = 123,
|
||||
5..9 = 54,
|
||||
10..<16 = i*3 + (i-1)*2,
|
||||
};
|
||||
fmt.println(foo); // [123, 0, 0, 0, 0, 54, 54, 54, 54, 54, 8, 8, 8, 8, 8]
|
||||
{ // Indexed
|
||||
foo := [?]int{
|
||||
3 = 16,
|
||||
1 = 4,
|
||||
2 = 9,
|
||||
0 = 1,
|
||||
};
|
||||
fmt.println(foo);
|
||||
}
|
||||
{ // Ranges
|
||||
i := 2;
|
||||
foo := [?]int {
|
||||
0 = 123,
|
||||
5..9 = 54,
|
||||
10..<16 = i*3 + (i-1)*2,
|
||||
};
|
||||
#assert(len(foo) == 16);
|
||||
fmt.println(foo); // [123, 0, 0, 0, 0, 54, 54, 54, 54, 54, 8, 8, 8, 8, 8]
|
||||
}
|
||||
{ // Slice and Dynamic Array support
|
||||
i := 2;
|
||||
foo_slice := []int {
|
||||
0 = 123,
|
||||
5..9 = 54,
|
||||
10..<16 = i*3 + (i-1)*2,
|
||||
};
|
||||
assert(len(foo) == 16);
|
||||
fmt.println(foo_slice); // [123, 0, 0, 0, 0, 54, 54, 54, 54, 54, 8, 8, 8, 8, 8]
|
||||
|
||||
foo_dynamic_array := [dynamic]int {
|
||||
0 = 123,
|
||||
5..9 = 54,
|
||||
10..<16 = i*3 + (i-1)*2,
|
||||
};
|
||||
assert(len(foo) == 16);
|
||||
fmt.println(foo_dynamic_array); // [123, 0, 0, 0, 0, 54, 54, 54, 54, 54, 8, 8, 8, 8, 8]
|
||||
}
|
||||
}
|
||||
|
||||
main :: proc() {
|
||||
|
||||
+6
-3
@@ -7205,10 +7205,13 @@ ExprKind check_expr_base_internal(CheckerContext *c, Operand *o, Ast *node, Type
|
||||
|
||||
i64 lo = exact_value_to_i64(x.value);
|
||||
i64 hi = exact_value_to_i64(y.value);
|
||||
i64 max_index = hi;
|
||||
if (op.kind == Token_RangeHalf) {
|
||||
hi -= 1;
|
||||
}
|
||||
i64 max_index = hi;
|
||||
if (op.kind == Token_Ellipsis) {
|
||||
max_index += 1;
|
||||
}
|
||||
|
||||
bool new_range = range_cache_add_range(&rc, lo, hi);
|
||||
if (!new_range) {
|
||||
@@ -7257,8 +7260,8 @@ ExprKind check_expr_base_internal(CheckerContext *c, Operand *o, Ast *node, Type
|
||||
continue;
|
||||
}
|
||||
|
||||
if (max < index) {
|
||||
max = index;
|
||||
if (max < index+1) {
|
||||
max = index+1;
|
||||
}
|
||||
|
||||
Operand operand = {};
|
||||
|
||||
Reference in New Issue
Block a user