...
 
Commits (4)
......@@ -665,6 +665,15 @@ fn split_items(
}
}
});
let storage_ident = &storage.ident;
for item_impl in &impl_blocks {
if item_impl.self_ty != storage_ident.to_string() {
bail!(
item_impl.self_ty,
"ink! impl blocks need to be implemented for the #[ink(storage)] struct"
)
}
}
let functions = impl_blocks
.into_iter()
.map(|impl_block| impl_block.functions)
......
......@@ -39,4 +39,5 @@ fn compile_tests() {
t.compile_fail("tests/ui/fail/13-abi-constructor.rs");
t.compile_fail("tests/ui/fail/14-missing-storage-struct.rs");
t.compile_fail("tests/ui/fail/15-multiple-storage-structs.rs");
t.compile_fail("tests/ui/fail/16-storage-impl-ident-conflict.rs");
}
#![feature(proc_macro_hygiene)]
use ink_lang2 as ink;
#[ink::contract(version = "0.1.0")]
mod noop {
// This test ensures that ink! impl blocks are always
// implemented on the only storage struct definition.
#[ink(storage)]
struct StorageStruct {}
// This ink! impl block is okay.
impl StorageStruct {
#[ink(constructor)]
fn new1(&mut self) {}
#[ink(message)]
fn do_something1(&self) {}
}
// Missing the #[ink(storage)] attribute on purpose.
struct NonStorageStruct {}
// This ink! impl block is invalid in that it implement
// the messages and constructors for a non-existing ink!
// storage struct. We expect a failure here.
impl NonStorageStruct {
#[ink(constructor)]
fn new2(&mut self) {}
#[ink(message)]
fn do_something2(&self) {}
}
}
fn main() {}
error: ink! impl blocks need to be implemented for the #[ink(storage)] struct
--> $DIR/16-storage-impl-ident-conflict.rs:28:10
|
28 | impl NonStorageStruct {
| ^^^^^^^^^^^^^^^^
......@@ -18,7 +18,7 @@ mod incrementer {
by: i32,
}
impl Flipper {
impl Incrementer {
#[ink(constructor)]
fn new(&mut self, init_value: i32) {
self.value.set(init_value as i64);
......
......@@ -32,7 +32,7 @@ mod erc20 {
amount: Balance,
}
impl Flipper {
impl Erc20 {
#[ink(constructor)]
fn new(&mut self, initial_supply: Balance) {
let caller = self.env().caller();
......