c3c icon indicating copy to clipboard operation
c3c copied to clipboard

Assertion when has_tagof is accidentally called on fn type

Open Dodzey opened this issue 1 year ago • 2 comments

This was a typo in my code, but rather than a nice error message it produced a nasty assertion

struct Foo { int a; }
struct Bar { int a; }
fn void Bar.xyz(&self) @tag("footag", 123) {}
macro void Foo.tags(&self, other)
{
    // inner to remove pointer
    var $Type = $typefrom($typeof(other).inner);
    $echo "$Type is " +++ $Type.nameof;
    var $methodcount = $Type.methodsof.len;
    $for (var $i = 0; $i < $methodcount; $i++)
        //var $MethodType = $typeof($Type.$eval($Type.methodsof[$i])); // OK
        var $MethodType = $typeof(&$Type.$eval($Type.methodsof[$i])); // BAD
                            //    ^ TYPO &
        $echo "$MethodType is " +++ $MethodType.nameof;
        var $hasfootag = $MethodType.has_tagof("footag");
    $endfor
}
fn void main() { Bar bar; Foo foo; foo.tags(&bar); }

Output

] $Type is Bar
] $MethodType is fn void(Bar*)
Assertion failed: (decl->resolved_attributes), function sema_expr_analyse_tagof, file sema_expr.c, line 2498.
zsh: abort      c3c compile repro-tags.c3

Dodzey avatar Aug 10 '24 19:08 Dodzey

This should work now.

lerno avatar Aug 11 '24 15:08 lerno

Please check and close the issue if it is ok.

lerno avatar Aug 23 '24 17:08 lerno

Both forms now report $MethodType is fn void(Bar*)

Dodzey avatar Sep 01 '24 21:09 Dodzey