Fix slice indexing in example
This commit is contained in:
@@ -306,7 +306,7 @@ gen_expr(Ast_Expr *ast, Ast_Type *type_of_var){
|
||||
if(!(type_of_var && type_of_var == type_pointer_to_char))
|
||||
gen(".str");
|
||||
}
|
||||
else if(is_slice(node->resolved_type)){
|
||||
else if(is_slice(node->index_original_type)){
|
||||
gen(".data");
|
||||
}
|
||||
gen("[");
|
||||
|
||||
@@ -33,7 +33,6 @@ main :: (): int
|
||||
// We set all variables to 1 so
|
||||
assert(static_array[6] == 1)
|
||||
|
||||
|
||||
// This is how slice is defined, no [] index in between brackets
|
||||
// slice is array pointer + length
|
||||
// Other then that it works exactly like regular array
|
||||
@@ -41,4 +40,11 @@ main :: (): int
|
||||
|
||||
// We can't do a compile time assert anymore
|
||||
assert(length_of(slice) == 8)
|
||||
assert(slice[4] == 1)
|
||||
|
||||
// After we loop and reassign slice values
|
||||
// old static_array gets changed
|
||||
for slice
|
||||
*it = 2
|
||||
|
||||
assert(static_array[2] == 2)
|
||||
Reference in New Issue
Block a user