summaryrefslogtreecommitdiff
path: root/types.c
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2019-10-21 10:08:40 -0400
committerLeo Tenenbaum <pommicket@gmail.com>2019-10-21 10:08:40 -0400
commitee7525251681a3c0ab38e0356bc3733adb3e6566 (patch)
tree9e2ded4a9de3823419375b1c31a7d4973279e2f3 /types.c
parentd85766938a25c5c8fc32cdb83ee61b983d458318 (diff)
run time slice at index; started compile time
Diffstat (limited to 'types.c')
-rw-r--r--types.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/types.c b/types.c
index 1a92427..5612eb3 100644
--- a/types.c
+++ b/types.c
@@ -979,13 +979,20 @@ static bool types_expr(Typer *tr, Expression *e) {
err_print(e->where, "The index of an array must be a builtin numerical type.");
return false;
}
- if (lhs_type->kind != TYPE_ARR) {
- char *s = type_to_str(lhs_type);
+ switch (lhs_type->kind) {
+ case TYPE_ARR:
+ *t = *lhs_type->arr.of;
+ break;
+ case TYPE_SLICE:
+ *t = *lhs_type->slice;
+ break;
+ default: {
+ char *s = type_to_str(lhs_type);
err_print(e->where, "Trying to take index of non-array type %s.", s);
free(s);
return false;
}
- *t = *lhs_type->arr.of;
+ }
break;
} break;
} break;