diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-10-01 14:01:51 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-10-01 14:01:51 -0400 |
| commit | 7494c89a4e1baa08a2720817b06676b34eebb284 (patch) | |
| tree | 5b042252242d218cbbdb9a6448b9d04d3f41c27f /src/typecheck.c | |
| parent | 235dbc07a9dd15967cebe136342249372b0285e0 (diff) | |
Fixes for indexing into lists with optional item types
Diffstat (limited to 'src/typecheck.c')
| -rw-r--r-- | src/typecheck.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/typecheck.c b/src/typecheck.c index 3c820fa9..eff894be 100644 --- a/src/typecheck.c +++ b/src/typecheck.c @@ -934,8 +934,10 @@ type_t *get_type(env_t *env, ast_t *ast) { if (value_t->tag == ListType) { if (!indexing->index) return indexed_t; type_t *index_t = get_type(env, indexing->index); - if (index_t->tag == IntType || index_t->tag == BigIntType || index_t->tag == ByteType) - return Type(OptionalType, Match(value_t, ListType)->item_type); + if (index_t->tag == IntType || index_t->tag == BigIntType || index_t->tag == ByteType) { + type_t *item_type = Match(value_t, ListType)->item_type; + return item_type->tag == OptionalType ? item_type : Type(OptionalType, item_type); + } code_err(indexing->index, "I only know how to index lists using integers, not ", type_to_text(index_t)); } else if (value_t->tag == TableType) { DeclareMatch(table_type, value_t, TableType); |
