Forbid stray tokens in call index (#13036)

* Check for call_index

* fixes

* pallet ui test for weight attribute

* Update frame/support/procedural/src/pallet/parse/call.rs

Co-authored-by: Bastian Köcher <git@kchr.de>

* fix

* small fix

* wrong return type

* ...

* .

* final fix

* update .stderr

* commit

* udpate

* Update frame/support/procedural/src/pallet/parse/call.rs

Co-authored-by: Bastian Köcher <git@kchr.de>

* update .stderr

Co-authored-by: Bastian Köcher <git@kchr.de>
This commit is contained in:
Sergej Sakac
2023-01-02 11:23:33 +01:00
committed by GitHub
parent 9c69fc1b32
commit 5af801ce60
5 changed files with 91 additions and 0 deletions
@@ -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<T>(core::marker::PhantomData<T>);
#[pallet::call]
impl<T: Config> Pallet<T> {
#[pallet::call_index(0something)]
pub fn foo(origin: OriginFor<T>) -> DispatchResultWithPostInfo {}
}
}
fn main() {
}
@@ -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)]
| ^^^^^^^^^^
@@ -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<T>(core::marker::PhantomData<T>);
#[pallet::call]
impl<T: Config> Pallet<T> {
#[pallet::call_index(0)]
#[pallet::weight(10_000something)]
pub fn foo(origin: OriginFor<T>) -> DispatchResultWithPostInfo { Ok(().into()) }
}
}
fn main() {
}
@@ -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;
| ^^^^^^^^