summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--eval.c4
-rw-r--r--main.c1
-rw-r--r--types.c7
3 files changed, 12 insertions, 0 deletions
diff --git a/eval.c b/eval.c
index 9c55a06..f0b53b9 100644
--- a/eval.c
+++ b/eval.c
@@ -594,6 +594,10 @@ static void eval_deref_set(void *set, Value *to, Type *type) {
}
static Status eval_val_ptr_at_index(Location where, void *arr_ptr, U64 i, Type *arr_type, void **ptr, Type **type) {
+ if (arr_type->kind == TYPE_PTR) {
+ arr_type = arr_type->ptr;
+ arr_ptr = *(void **)arr_ptr;
+ }
switch (arr_type->kind) {
case TYPE_ARR: {
U64 arr_sz = (U64)arr_type->arr->n;
diff --git a/main.c b/main.c
index 4934520..78e79a9 100644
--- a/main.c
+++ b/main.c
@@ -9,6 +9,7 @@ see development.md for development information
@TODO:
see note in types.c : we probably shouldn't go to the trouble of evaluating this (just do this stuff if it's an ident)
+ensure that in s[a:b] s is an l-value
figure out how printf is gonna work
make error when you give too few arguments better
when putf is done, migrate tests to new std
diff --git a/types.c b/types.c
index 52ea5e0..166bda0 100644
--- a/types.c
+++ b/types.c
@@ -2792,6 +2792,13 @@ static Status types_expr(Typer *tr, Expression *e) {
if (lhs_type->kind == TYPE_PTR) {
lhs_type = lhs_type->ptr;
}
+
+ // in order to index an array, we need a pointer to it
+ if (lhs_type->kind == TYPE_ARR && !expr_must_lval(lhs, "access an index of")) {
+ info_print(lhs->where, "Maybe try extracting this into a variable.");
+ return false;
+ }
+
switch (lhs_type->kind) {
case TYPE_ARR:
*t = *lhs_type->arr->of;