[BUG] Introspect derive macro fail
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
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?
@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 🤔
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 👍
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.
fixed in latest version