dojo icon indicating copy to clipboard operation
dojo copied to clipboard

[BUG] Introspect derive macro fail

Open notV4l opened this issue 9 months ago • 4 comments

Describe the bug Introspect derive macro will fail for a Span/Array if it's last field and doesnt end by comma & have a comment

Not Ok

#[derive(Copy, Drop, Serde, Introspect)]
#[dojo::model]
pub struct MyModel {
    #[key]
    pub id: u32,
    pub array: Span<u32> // comment <-- fail :(
}

Ok

#[derive(Copy, Drop, Serde, Introspect)]
#[dojo::model]
pub struct MyModel {
    #[key]
    pub id: u32,
    pub array: Span<u32>, // comment
}

Additional context 1.4.0

notV4l avatar Apr 25 '25 11:04 notV4l

Ah, nice edge case.

@remybar do you think this is something that's solved by the proc macros parsing, or it's still very similar in how the DB is used?

glihm avatar Apr 25 '25 14:04 glihm

@notV4l @glihm

Nice catch ! Thanks @notV4l 👍

I have to look at this weird bug but I think this is a bug in the Cairo parser crate (the one which builds the AST) so we will have the same issue with proc macros. If it's a bug in the Cairo parser, I will create an issue on the Starkware repo 🤔

remybar avatar Apr 25 '25 16:04 remybar

Ok, I have the same issue in my small dojo_proc_macro repo and the issue comes from dojo-lang in this function: https://github.com/dojoengine/dojo/blob/1345f9cc20e0769a19de7a8e9a3e5a1564fb3797/crates/dojo/lang/src/derive_macros/introspect/utils.rs#L42-L48

The strip_suffix(...).unwrap() call crashes because of the comment. I will fix it in a PR, thanks 👍

remybar avatar Apr 25 '25 17:04 remybar

Issue reported to Starkware repo: https://github.com/starkware-libs/cairo/issues/7706. But the proposed PR makes Dojo struct processing more robust by using regex and so is not impacted by comments.

remybar avatar Apr 26 '25 09:04 remybar

fixed in latest version

notV4l avatar Aug 25 '25 13:08 notV4l