~sircmpwn/hare-dev

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
2 2

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

Details
Message ID
<20230704122449.609423-1-jummit@web.de>
DKIM signature
missing
Download raw message
Patch: +1 -2
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

[harec/patches] build success

builds.sr.ht <builds@sr.ht>
Details
Message ID
<CTTDYWILXERP.H8T4X7KSF9O8@cirno2>
In-Reply-To
<20230704122449.609423-1-jummit@web.de> (view parent)
DKIM signature
missing
Download raw message
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]: 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
Details
Message ID
<CUJ71X5CCM11.FX1IQLCQPCXD@monch>
In-Reply-To
<20230704122449.609423-1-jummit@web.de> (view parent)
DKIM signature
missing
Download raw message
sorry for the delayed review. mind adding a test for this? in
tests/26-regression.ha
Reply to thread Export thread (mbox)