diff options
| -rw-r--r-- | typecheck.c | 3 | ||||
| -rw-r--r-- | types.c | 8 |
2 files changed, 7 insertions, 4 deletions
diff --git a/typecheck.c b/typecheck.c index 7f655606..2b5dd701 100644 --- a/typecheck.c +++ b/typecheck.c @@ -98,7 +98,8 @@ type_t *parse_type_ast(env_t *env, type_ast_t *ast) code_err(ast, "Tables with optional-typed values are not currently supported"); return Type(TableType, .key_type=key_type, .value_type=val_type); } else if (table_type->default_value) { - type_t *t = Type(TableType, .key_type=key_type, .default_value=table_type->default_value); + type_t *t = Type(TableType, .key_type=key_type, + .value_type=get_type(env, table_type->default_value), .default_value=table_type->default_value); if (has_stack_memory(t)) code_err(ast, "Tables can't have stack references because the array may outlive the stack frame."); return t; @@ -377,15 +377,17 @@ PUREFUNC bool can_promote(type_t *actual, type_t *needed) if (needed->tag == PointerType && actual->tag == PointerType) { auto needed_ptr = Match(needed, PointerType); auto actual_ptr = Match(actual, PointerType); + + if (actual_ptr->is_stack && !needed_ptr->is_stack) + // Can't use &x for a function that wants a @Foo or ?Foo + return false; + if (needed_ptr->pointed->tag == TableType && actual_ptr->pointed->tag == TableType) return can_promote(actual_ptr->pointed, needed_ptr->pointed); else if (needed_ptr->pointed->tag != MemoryType && !type_eq(needed_ptr->pointed, actual_ptr->pointed)) // Can't use @Foo for a function that wants @Baz // But you *can* use @Foo for a function that wants @Memory return false; - else if (actual_ptr->is_stack && !needed_ptr->is_stack) - // Can't use &x for a function that wants a @Foo or ?Foo - return false; else return true; } |
