commit 8ced1ca30f987d1c22165e947bd83163c929d2ae
parent cdcbfb725db71f4b393ff8f97b2b0d8ed9f5fa31
Author: Drew DeVault <sir@cmpwn.com>
Date: Sun, 24 Jan 2021 15:18:17 -0500
Loosen pointer assignment rules
This'll get cleaned up when we address const
Diffstat:
2 files changed, 11 insertions(+), 7 deletions(-)
diff --git a/src/check.c b/src/check.c
@@ -1186,7 +1186,8 @@ check_expr_struct(struct context *ctx,
expect(&aexpr->loc, field, "No field by this name exists for this type");
expect(&aexpr->loc,
type_is_assignable(ctx->store, field->type, sexpr->value->result),
- "Cannot initialize struct field from value of this type");
+ "Cannot initialize struct field '%s' from value of this type",
+ field->name);
sexpr->field = field;
sexpr->value = lower_implicit_cast(field->type, sexpr->value);
diff --git a/src/type_store.c b/src/type_store.c
@@ -110,25 +110,28 @@ type_is_assignable(struct type_store *store,
case TYPE_STORAGE_F64:
return type_is_float(from);
case TYPE_STORAGE_POINTER:
+ to_secondary = type_store_lookup_with_flags(store,
+ to->pointer.referent, 0);
+
switch (from->storage) {
case TYPE_STORAGE_UINTPTR:
return true;
case TYPE_STORAGE_NULL:
return to->pointer.flags & PTR_NULLABLE;
case TYPE_STORAGE_POINTER:
- switch (to->pointer.referent->storage) {
+ from_secondary = type_store_lookup_with_flags(store,
+ from->pointer.referent, 0);
+ switch (to_secondary->storage) {
case TYPE_STORAGE_VOID:
- // TODO: const transitivity
- return to->pointer.referent->flags == from->pointer.referent->flags;
+ return true;
case TYPE_STORAGE_ARRAY:
if (type_is_assignable(store,
- to->pointer.referent,
- from->pointer.referent)) {
+ to_secondary, from_secondary)) {
return true;
}
break;
default:
- if (to->pointer.referent != from->pointer.referent) {
+ if (to_secondary != from_secondary) {
return false;
}
break;