Skip to content

Commit 9fbe73f

Browse files
committed
Fix macro
1 parent e416f0a commit 9fbe73f

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

crates/ink/ir/src/ir/selector.rs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use super::blake2::blake2b_256;
1616
use crate::literal::HexLiteral;
1717
use proc_macro2::TokenStream as TokenStream2;
18+
use quote::ToTokens;
1819
use std::marker::PhantomData;
1920
use syn::{
2021
parse::Parser,
@@ -270,13 +271,25 @@ impl<T> TryFrom<TokenStream2> for SelectorMacro<T> {
270271
};
271272

272273
// Parse the literal (second argument)
274+
// We need to handle both direct literals and literals passed through declarative
275+
// macros. When a literal is captured by a declarative macro and passed through,
276+
// it may not be recognized as syn::Expr::Lit. In such cases, we try to parse
277+
// the expression's token stream directly as a literal.
273278
let lit = match &exprs[1] {
274279
syn::Expr::Lit(expr_lit) => expr_lit.lit.clone(),
275-
invalid => {
276-
return Err(format_err!(
277-
invalid.span(),
278-
"expected string or byte string literal as second argument",
279-
))
280+
other_expr => {
281+
// Try to parse the expression's tokens directly as a literal
282+
// This handles cases where literals are passed through declarative macros
283+
let tokens = other_expr.to_token_stream();
284+
match syn::parse2::<syn::Lit>(tokens) {
285+
Ok(lit) => lit,
286+
Err(_) => {
287+
return Err(format_err!(
288+
other_expr.span(),
289+
"expected string or byte string literal as second argument",
290+
))
291+
}
292+
}
280293
}
281294
};
282295

crates/ink/ir/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ pub use self::{
7171
Namespace,
7272
Receiver,
7373
Selector,
74+
SelectorAbi,
7475
SelectorMacro,
7576
SignatureTopic,
7677
Storage,

0 commit comments

Comments
 (0)