Missed constructor and messages not critical error during compilation
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.
Hello,someone tracking this?If not,I would like to pick it up.
@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.
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.
@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.
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 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.
It's ok.Good for hear that.
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.