Signed-off-by: Jummit <jummit@web.de>
---
This crash occurs in a very specific configuration:
// This doesn't even have to be declared.
type shadow = struct {
name: int,
};
// It crashes because the "shadow" type is expected to be a struct
// but is a parameter in this case.
// It only occurs when the return type isn't void but the function
// returns void.
fn take(shadow: str) str = {
yield;
};
fn give() void = {
// Here is the lookup, in the context of a parameter list.
take(shadow {
name = 1,
});
};
Previously this code would crash the compiler:
harec: src/check.c:2767: check_expr_struct: Assertion `obj->otype == O_TYPE' failed.
It is possible that there is a deeper issue here, this is just a quick
fix I came up with after my first look at the responsible code.
src/check.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/src/check.c b/src/check.c
index b0f7239..844ffa5 100644
--- a/src/check.c
+++ b/src/check.c
@@ -2758,12 +2758,11 @@ check_expr_struct(struct context *ctx,
&aexpr->_struct.type);
// resolve the unknown type
wrap_resolver(ctx, obj, resolve_type);
- if (!obj) {
+ if (!obj || obj->otype != O_TYPE) {
error(ctx, aexpr->loc, expr,
"Unknown type alias");
return;
}
- assert(obj->otype == O_TYPE);
stype = obj->type;
enum type_storage storage = type_dealias(stype)->storage;
if (storage != STORAGE_STRUCT && storage != STORAGE_UNION) {
--
2.41.0