harec: Fix crash when struct name is shadowed by parameter v1 NEEDS REVISION

Jummit: 1
 Fix crash when struct name is shadowed by parameter

 1 files changed, 1 insertions(+), 2 deletions(-)
#1018480 alpine.yml success
#1018481 freebsd.yml success
#1018482 netbsd.yml success
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~sircmpwn/hare-dev/patches/42376/mbox | git am -3
Learn more about email & git

[PATCH harec] Fix crash when struct name is shadowed by parameter Export this patch

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 = {

    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,
		// 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");
		assert(obj->otype == O_TYPE);
		stype = obj->type;
		enum type_storage storage = type_dealias(stype)->storage;
		if (storage != STORAGE_STRUCT && storage != STORAGE_UNION) {
harec/patches: SUCCESS in 1m4s

[Fix crash when struct name is shadowed by parameter][0] from [Jummit][1]

[0]: https://lists.sr.ht/~sircmpwn/hare-dev/patches/42376
[1]: mailto:jummit@web.de

✓ #1018481 SUCCESS harec/patches/freebsd.yml https://builds.sr.ht/~sircmpwn/job/1018481
✓ #1018482 SUCCESS harec/patches/netbsd.yml  https://builds.sr.ht/~sircmpwn/job/1018482
✓ #1018480 SUCCESS harec/patches/alpine.yml  https://builds.sr.ht/~sircmpwn/job/1018480
sorry for the delayed review. mind adding a test for this? in