diff --git a/CHANGELOG.md b/CHANGELOG.md index ff95b1066b..1e54bc9fd5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +- Rename `_checked` codegen call methods with `try_` ‒ [#1621](https://github.com/paritytech/ink/pull/1621) + +### Breaking Changes + +1. We've renamed some of the generated message methods on the `ContractRef` struct. They + have been changed from `_checked` to `try_` ([#1621](https://github.com/paritytech/ink/pull/1621)) ## Version 4.0.0-beta.1 The coolest feature included in this release is the first first published version of diff --git a/crates/ink/codegen/src/generator/as_dependency/contract_ref.rs b/crates/ink/codegen/src/generator/as_dependency/contract_ref.rs index 42537d034d..26ee2f58e5 100644 --- a/crates/ink/codegen/src/generator/as_dependency/contract_ref.rs +++ b/crates/ink/codegen/src/generator/as_dependency/contract_ref.rs @@ -364,7 +364,7 @@ impl ContractRef<'_> { .filter_attr(message.attrs().to_vec()); let storage_ident = self.contract.module().storage().ident(); let message_ident = message.ident(); - let checked_message_ident = message.checked_ident(); + let try_message_ident = message.try_ident(); let call_operator = match message.receiver() { ir::Receiver::Ref => quote! { call }, ir::Receiver::RefMut => quote! { call_mut }, @@ -381,7 +381,7 @@ impl ContractRef<'_> { & #mut_token self #( , #input_bindings : #input_types )* ) #output_type { - self.#checked_message_ident( #( #input_bindings, )* ) + self.#try_message_ident( #( #input_bindings, )* ) .unwrap_or_else(|error| ::core::panic!( "encountered error while calling {}::{}: {:?}", ::core::stringify!(#storage_ident), @@ -392,7 +392,7 @@ impl ContractRef<'_> { #( #attrs )* #[inline] - pub fn #checked_message_ident( + pub fn #try_message_ident( & #mut_token self #( , #input_bindings : #input_types )* ) -> #wrapped_output_type { diff --git a/crates/ink/ir/src/ir/item_impl/message.rs b/crates/ink/ir/src/ir/item_impl/message.rs index f48814b427..04a3a08afe 100644 --- a/crates/ink/ir/src/ir/item_impl/message.rs +++ b/crates/ink/ir/src/ir/item_impl/message.rs @@ -317,9 +317,9 @@ impl Message { utils::local_message_id(self.ident()) } - /// Returns the identifier of the message with an additional `_checked` suffix attached. - pub fn checked_ident(&self) -> Ident { - quote::format_ident!("{}_checked", self.ident()) + /// Returns the identifier of the message with an additional `try_` prefix attached. + pub fn try_ident(&self) -> Ident { + quote::format_ident!("try_{}", self.ident()) } } diff --git a/crates/ink/tests/ui/contract/fail/message-hygiene-checked.stderr b/crates/ink/tests/ui/contract/fail/message-hygiene-checked.stderr deleted file mode 100644 index 8e64a7e9f8..0000000000 --- a/crates/ink/tests/ui/contract/fail/message-hygiene-checked.stderr +++ /dev/null @@ -1,8 +0,0 @@ -error[E0592]: duplicate definitions with name `message_checked` - --> tests/ui/contract/fail/message-hygiene-checked.rs:16:9 - | -1 | #[ink::contract] - | ---------------- other definition for `message_checked` -... -16 | pub fn message_checked(&self) {} - | ^^^ duplicate definitions for `message_checked` diff --git a/crates/ink/tests/ui/contract/fail/message-hygiene-checked.rs b/crates/ink/tests/ui/contract/fail/message-hygiene-try.rs similarity index 88% rename from crates/ink/tests/ui/contract/fail/message-hygiene-checked.rs rename to crates/ink/tests/ui/contract/fail/message-hygiene-try.rs index 4f1c844ceb..749a70efdf 100644 --- a/crates/ink/tests/ui/contract/fail/message-hygiene-checked.rs +++ b/crates/ink/tests/ui/contract/fail/message-hygiene-try.rs @@ -13,7 +13,7 @@ mod contract { pub fn message(&self) {} #[ink(message)] - pub fn message_checked(&self) {} + pub fn try_message(&self) {} } } diff --git a/crates/ink/tests/ui/contract/fail/message-hygiene-try.stderr b/crates/ink/tests/ui/contract/fail/message-hygiene-try.stderr new file mode 100644 index 0000000000..ad3c2b27ac --- /dev/null +++ b/crates/ink/tests/ui/contract/fail/message-hygiene-try.stderr @@ -0,0 +1,8 @@ +error[E0592]: duplicate definitions with name `try_message` + --> tests/ui/contract/fail/message-hygiene-try.rs:16:9 + | +1 | #[ink::contract] + | ---------------- other definition for `try_message` +... +16 | pub fn try_message(&self) {} + | ^^^ duplicate definitions for `try_message` diff --git a/examples/lang-err-integration-tests/contract-ref/lib.rs b/examples/lang-err-integration-tests/contract-ref/lib.rs index a6dac8aee3..244ba2856e 100755 --- a/examples/lang-err-integration-tests/contract-ref/lib.rs +++ b/examples/lang-err-integration-tests/contract-ref/lib.rs @@ -48,7 +48,7 @@ mod contract_ref { #[ink(message)] pub fn flip_check(&mut self) { self.flipper - .flip_checked() + .try_flip() .expect("The ink! codegen should've produced a valid call."); } @@ -60,7 +60,7 @@ mod contract_ref { #[ink(message)] pub fn get_check(&mut self) -> bool { self.flipper - .get_checked() + .try_get() .expect("The ink! codegen should've produced a valid call.") } }