diff --git a/frame/support/procedural/src/pallet/parse/call.rs b/frame/support/procedural/src/pallet/parse/call.rs index 9620038edfd6d..3af3225484fae 100644 --- a/frame/support/procedural/src/pallet/parse/call.rs +++ b/frame/support/procedural/src/pallet/parse/call.rs @@ -93,6 +93,10 @@ impl syn::parse::Parse for FunctionAttr { let call_index_content; syn::parenthesized!(call_index_content in content); let index = call_index_content.parse::()?; + if !index.suffix().is_empty() { + let msg = "Number literal must not have a suffix"; + return Err(syn::Error::new(index.span(), msg)) + } Ok(FunctionAttr::CallIndex(index.base10_parse()?)) } else { Err(lookahead.error()) diff --git a/frame/support/test/tests/pallet_ui/call_index_has_suffix.rs b/frame/support/test/tests/pallet_ui/call_index_has_suffix.rs new file mode 100644 index 0000000000000..abe4dc199bf51 --- /dev/null +++ b/frame/support/test/tests/pallet_ui/call_index_has_suffix.rs @@ -0,0 +1,20 @@ +#[frame_support::pallet] +mod pallet { + use frame_support::pallet_prelude::DispatchResultWithPostInfo; + use frame_system::pallet_prelude::OriginFor; + + #[pallet::config] + pub trait Config: frame_system::Config {} + + #[pallet::pallet] + pub struct Pallet(core::marker::PhantomData); + + #[pallet::call] + impl Pallet { + #[pallet::call_index(0something)] + pub fn foo(origin: OriginFor) -> DispatchResultWithPostInfo {} + } +} + +fn main() { +} diff --git a/frame/support/test/tests/pallet_ui/call_index_has_suffix.stderr b/frame/support/test/tests/pallet_ui/call_index_has_suffix.stderr new file mode 100644 index 0000000000000..2f4cead6cf70c --- /dev/null +++ b/frame/support/test/tests/pallet_ui/call_index_has_suffix.stderr @@ -0,0 +1,5 @@ +error: Number literal must not have a suffix + --> tests/pallet_ui/call_index_has_suffix.rs:14:30 + | +14 | #[pallet::call_index(0something)] + | ^^^^^^^^^^ diff --git a/frame/support/test/tests/pallet_ui/weight_argument_has_suffix.rs b/frame/support/test/tests/pallet_ui/weight_argument_has_suffix.rs new file mode 100644 index 0000000000000..99195d21be62e --- /dev/null +++ b/frame/support/test/tests/pallet_ui/weight_argument_has_suffix.rs @@ -0,0 +1,21 @@ +#[frame_support::pallet] +mod pallet { + use frame_support::pallet_prelude::DispatchResultWithPostInfo; + use frame_system::pallet_prelude::OriginFor; + + #[pallet::config] + pub trait Config: frame_system::Config {} + + #[pallet::pallet] + pub struct Pallet(core::marker::PhantomData); + + #[pallet::call] + impl Pallet { + #[pallet::call_index(0)] + #[pallet::weight(10_000something)] + pub fn foo(origin: OriginFor) -> DispatchResultWithPostInfo { Ok(().into()) } + } +} + +fn main() { +} diff --git a/frame/support/test/tests/pallet_ui/weight_argument_has_suffix.stderr b/frame/support/test/tests/pallet_ui/weight_argument_has_suffix.stderr new file mode 100644 index 0000000000000..c9b2010f88bb3 --- /dev/null +++ b/frame/support/test/tests/pallet_ui/weight_argument_has_suffix.stderr @@ -0,0 +1,41 @@ +error: invalid suffix `something` for number literal + --> tests/pallet_ui/weight_argument_has_suffix.rs:15:26 + | +15 | #[pallet::weight(10_000something)] + | ^^^^^^^^^^^^^^^ invalid suffix `something` + | + = help: the suffix must be one of the numeric types (`u32`, `isize`, `f32`, etc.) + +error[E0308]: mismatched types + --> tests/pallet_ui/weight_argument_has_suffix.rs:12:12 + | +12 | #[pallet::call] + | ^^^^ + | | + | expected trait `frame_support::dispatch::ClassifyDispatch`, found trait `frame_support::dispatch::WeighData` + | arguments to this function are incorrect + | + = note: expected reference `&dyn frame_support::dispatch::ClassifyDispatch<()>` + found reference `&dyn frame_support::dispatch::WeighData<()>` +note: associated function defined here + --> $WORKSPACE/frame/support/src/dispatch.rs + | + | fn classify_dispatch(&self, target: T) -> DispatchClass; + | ^^^^^^^^^^^^^^^^^ + +error[E0308]: mismatched types + --> tests/pallet_ui/weight_argument_has_suffix.rs:12:12 + | +12 | #[pallet::call] + | ^^^^ + | | + | expected trait `frame_support::dispatch::PaysFee`, found trait `frame_support::dispatch::WeighData` + | arguments to this function are incorrect + | + = note: expected reference `&dyn frame_support::dispatch::PaysFee<()>` + found reference `&dyn frame_support::dispatch::WeighData<()>` +note: associated function defined here + --> $WORKSPACE/frame/support/src/dispatch.rs + | + | fn pays_fee(&self, _target: T) -> Pays; + | ^^^^^^^^