ink icon indicating copy to clipboard operation
ink copied to clipboard

Missed constructor and messages not critical error during compilation

Open xgreenx opened this issue 3 years ago • 8 comments

After the introduction of upgradable contracts, it is okay if some contracts don't have any message or constructor. Because they can be implemented in another code.

Instead of error during codegen, we can emit a warning and it is up to the user to fix it or not.

xgreenx avatar Mar 16 '22 18:03 xgreenx

Hello,someone tracking this?If not,I would like to pick it up.

willser avatar Mar 30 '22 13:03 willser

@willser For sure you could pick it!

I think the change needed in ink! is to make #[ink(constructor)]'s and #[ink(message)] optional, but require that at least one of them is defined. @xgreenx Is that also your understanding?

Instead of error during codegen, we can emit a warning and it is up to the user to fix it or not.

So for emitting this warning I don't think there's a way of doing this in ink!, we'll do it as a rule for the smart contract linter in cargo-contract instead. So that's nothing to be done as part of this ink! issue, it will require a follow-up issue in cargo-contract.

cmichi avatar Mar 30 '22 15:03 cmichi

As part of this ticket you should also add new tests in ink/crates/lang/tests/ui/contract/.

You can also remove the constructors in examples/upgradeable-contracts/delegate-calls/upgradeable-flipper/lib.rs then.

cmichi avatar Mar 30 '22 16:03 cmichi

@willser I need to revert my go from earlier today, there's some more stuff to consider here.

I'll try to post some more on it tomorrow, but please hold off until then.

cmichi avatar Mar 30 '22 19:03 cmichi

I thought it's a little change,so I has changed error to warning in lang mod,LOL.It work in this commit.

This is log when I remove the constructors and messages in `flipper`
warning: missing ink! message
  --> \\?\J:\code\ink\examples\flipper\lib.rs:6:1
   |
6  | / pub mod flipper {
7  | |     #[ink(storage)]
8  | |     pub struct Flipper {
9  | |         value: bool,
...  |
56 | |     }
57 | | }
   | |_^

warning: missing ink! constructor
  --> \\?\J:\code\ink\examples\flipper\lib.rs:6:1
   |
6  | / pub mod flipper {
7  | |     #[ink(storage)]
8  | |     pub struct Flipper {
9  | |         value: bool,
...  |
56 | |     }
57 | | }
   | |_^

warning: unreachable expression
  --> \\?\J:\code\ink\examples\flipper\lib.rs:8:5
   |
8  | /     pub struct Flipper {
9  | |         value: bool,
10 | |     }
   | |     ^
   | |     |
   | |_____unreachable expression
   |       any code following this expression is unreachable
   |
   = note: `#[warn(unreachable_code)]` on by default

warning: unused variable: `contract`
  --> \\?\J:\code\ink\examples\flipper\lib.rs:8:5
   |
8  | /     pub struct Flipper {
9  | |         value: bool,
10 | |     }
   | |_____^ help: if this is intentional, prefix it with an underscore: `_contract`
   |
   = note: `#[warn(unused_variables)]` on by default

warning: variable does not need to be mutable
  --> \\?\J:\code\ink\examples\flipper\lib.rs:8:5
   |
8  |       pub struct Flipper {
   |       ^---
   |       |
   |  _____help: remove this `mut`
   | |
9  | |         value: bool,
10 | |     }
   | |_____^
   |
   = note: `#[warn(unused_mut)]` on by default

But after reading your post I think things may be more complicated than I thought.So I am looking forward to your new post and suggestion,thank you.

willser avatar Mar 31 '22 11:03 willser

@willser Sorry for the delay, you're good to go. There was some discussion on if we actually want to make ink! messages and constructors optional and the decision is yes.

cmichi avatar Apr 07 '22 11:04 cmichi

It's ok.Good for hear that.

willser avatar Apr 08 '22 13:04 willser

Hello @cmichi ,there are some problem when I test a no-ink-message contract by using contracts-ui.I got error message TypeError: Cannot read properties of undefined (reading 'isPayable') when upload a no-ink-message contract.There are something need to be changed in contracts-ui(or substrate-contracts-node) I guess.

Other work is done and I will wait for your judgment on this problem before create a pr:change contracts-ui later or I understood or did something wrong.

willser avatar Apr 08 '22 14:04 willser