Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quote macro parsing bug #1992

Open
maciektr opened this issue Feb 18, 2025 · 0 comments
Open

Quote macro parsing bug #1992

maciektr opened this issue Feb 18, 2025 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@maciektr
Copy link
Contributor

maciektr commented Feb 18, 2025

Repro:

pub fn process(db: &SimpleParserDatabase, struct_ast: &ast::ItemStruct) -> TokenStream {

    let name_string = struct_ast.name(db).text(db).to_string();
    let name_token = TokenTree::Ident(Token::new(name_string.clone(), TextSpan::call_site()));

    let impl_string = format!("{}NameImpl", name_string.clone());
    let impl_token = TokenTree::Ident(Token::new(impl_string, TextSpan::call_site()));

    let res_string = format!("\"{}\"", name_string);
    let res_token = TokenTree::Ident(Token::new(res_string, TextSpan::call_site()));

    quote! {
        impl #impl_token of NameTrait<#name_token> {
            fn name(self: @#name_token) -> ByteArray {
                #res_token
            } 
        }
    }
}

generates:

 impl MyStructNameImplof NameTrait<MyStruct> {

Branch dev, https://github.com/software-mansion/scarb/blob/dev/plugins/cairo-lang-quote/src/lib.rs

@maciektr maciektr added this to Scarb Feb 18, 2025
@maciektr maciektr self-assigned this Feb 18, 2025
@maciektr maciektr converted this from a draft issue Feb 18, 2025
@maciektr maciektr added the bug Something isn't working label Feb 18, 2025
@maciektr maciektr assigned DelevoXDG and unassigned maciektr Feb 18, 2025
@DelevoXDG DelevoXDG moved this from Todo to In Progress in Scarb Feb 21, 2025
@maciektr maciektr added this to the Procedural macros milestone Feb 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: In Progress
Development

No branches or pull requests

2 participants