Skip to content

Commit

Permalink
Add typechecker for array access
Browse files Browse the repository at this point in the history
  • Loading branch information
arnav-ag committed Apr 10, 2024
1 parent 6b2fcab commit c31b013
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/vm/oogavm-typechecker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,29 @@ const type_comp = {
return method;
}
},
ArraySliceIndex: (comp, te, struct_te) => {
log('ArraySliceIndex');
log(unparse(comp));

const arrayType = type(comp.arrayExpression, te, struct_te);

if (!is_type(arrayType, ArrayType)) {
throw new TypecheckError('expected array type, got ' + unparse_types(arrayType));
}

assert(arrayType instanceof ArrayType, 'expected array type');

const indexType = type(comp.index, te, struct_te);

if (!is_type(indexType, IntegerType)) {
throw new TypecheckError('expected integer index, got ' + unparse_types(indexType));
}

comp.type = arrayType.elem_type;

log('Exiting ArraySliceIndex, returning', arrayType.elem_type);
return arrayType.elem_type;
},
};

/**
Expand Down

0 comments on commit c31b013

Please sign in to comment.