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

Rename _checked codegen call methods with try_ #1621

Merged
merged 5 commits into from
Jan 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand All @@ -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),
Expand All @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions crates/ink/ir/src/ir/item_impl/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ mod contract {
pub fn message(&self) {}

#[ink(message)]
pub fn message_checked(&self) {}
pub fn try_message(&self) {}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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`
4 changes: 2 additions & 2 deletions examples/lang-err-integration-tests/contract-ref/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}

Expand All @@ -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.")
}
}
Expand Down