aboutsummaryrefslogtreecommitdiff
path: root/types.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-12-22 16:37:09 -0500
committerBruce Hill <bruce@bruce-hill.com>2024-12-22 16:37:09 -0500
commitdf1b36cc278663f8376871b5f3d110c320315a36 (patch)
treec8c8dfd927174e3413d0ee6f2257c9618ea6110a /types.c
parentdcab9eb748bc092347c0f46565c9ff2c8933b06d (diff)
Fix issue with cross promotion for tables with default values
Diffstat (limited to 'types.c')
-rw-r--r--types.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/types.c b/types.c
index 5c37a686..ba866cf4 100644
--- a/types.c
+++ b/types.c
@@ -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;
}