-
Notifications
You must be signed in to change notification settings - Fork 431
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
Add Result<Self, Error>
return type for constructors
#1446
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1446 +/- ##
==========================================
- Coverage 70.89% 69.21% -1.68%
==========================================
Files 193 199 +6
Lines 6071 6124 +53
==========================================
- Hits 4304 4239 -65
- Misses 1767 1885 +118
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can not create a constructor that can safely fail without the need to panic!
I don't parse this sentence at all. Can you elaborate?
Also, why are we reliant on type aliases here while we aren't for messages? For messages we can just write any Result<T, E>
as return type. For constructors you would just stricten that to Result<Self, E>
and nothing more.
We aren't relying on type aliases at all. They are just used for convenience because I've seen them used in other examples like like DNS or ERC721. We can use
This is a typo, should be:
|
Ahh lol yeah this really fried my brain.
Good. I just misread the UI test I think. |
Update
If we are happy with my changes, I will add more UI tests to cover type aliases. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks a lot better now!
crates/ink/tests/ui/contract/fail/constructor-return-result-invalid.stderr
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
This PR closes #988.
The PR also includes an example
return_err
to illustrate the usage:Addition
If we define storage and error similar to
We can now create a constructor that can safely fail without the need to
panic!
Alternatively, you can define a type alias for convenience: