-
Notifications
You must be signed in to change notification settings - Fork 6k
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
modifier return values #49

Comments
I see two interpretations here, one is much simpler to implement but is less powerful:
|
I am also not sure how to do this properly. Please note that modifiers are very similar to macros and different from functions calling functions, especially with regards to |
What about just option 1 then? A lot of the time we use modifiers, we are implicitly using them as if they are attached to a function with a bool-like type which has two options: 0 or everything else (because modifiers "return 0" when they don't execute the |
Might make sense to make it a distinct language feature if it also imposes the constraint that the function has to be external. It might be deviating too far from what a modifier is supposed to be. |
Yes, option 1 sounds good. To summarize again: |
Option 1 works - a returns (...) format which must match the signature of any functions it's used on. Thanks for looking at this. |
It would be nice to solve point 2 as mentioned by @nmushegian. Maybe a simple solution would be not allowing modifiers to change the return value, but to capture and return it so that the modifier body after the i.e.
Where ret would be behave like a reference to the memory or like a tuple? @chriseth is that something remotely feasible? As a future progression, since you have the values as a variable, modifying/changing it could be introduced. |
@axic I don't see where your solution would be needed. If we change the |
@nmushegian if the modifier cannot return the return value, there is no need for capturing it. The modifier can just ignore the return value and it will be returned. |
I think I understand now, but I find it really unintuitive and still wish there was a way where
|
Instead of this: function multiplierOf(address _account)
public
returns (uint8 multiplier) {
if (accountTier3(_account)) return TIER_3_MULTIPLIER;
else if (accountTier2(_account)) return TIER_2_MULTIPLIER;
else return TIER_1_MULTIPLIER;
} I'd like to do this: function multiplierOf(address _account)
public
grantTier3(_account)
grantTier2(_account)
returns (uint8 multiplier) {
return TIER_1_MULTIPLIER;
}
modifier grantTier3(address _account)
returns (uint8 multiplier) {
if (accountTier3(_account)) return TIER_3_MULTIPLIER;
_;
}
modifier grantTier2(address _account)
returns (uint8 multiplier) {
if (accountTier2(_account)) return TIER_2_MULTIPLIER;
_;
} It keeps branches out of the body as recommended and splits out the checks for independent validation. |
EIP-8: devp2p Forward Compatibility Requirements for Homestead
As somebody that audits Solidity code I would recommend the contract author to use a different approach to increase readability. I do not see a good use for this feature. |
Hi there. I'm writing a Smart Contract that follows the StateMachine and AccessRestriction common patterns of Solidity for my thesis. Thank you :) |
Please use explicit enums and refer to those named enums in code, like all other state machines do. |
i will do that thanks!! mean while do you have any suggestion on how to receive a return value from a function into a modifier @fulldecent ? |
My answer will be application-specific. Please ping me from that project and let's discuss there. |
++ |
I have answers to all these questions. But here is not a forum. Please close this issue, there is no specific need to have a modifier return type. Here is what demonstration of a specific need looks like #3419 And I categorically assert that any Solidity program written with a modifier using return values can be written better without that feature. You are welcome to make a full question on a questions website, including code you wrote and your own research, and you can even ping me @fulldecent. I'm on all the sites. |
FWIW, I made a Twitter poll here: |
This issue has been marked as stale due to inactivity for the last 90 days. |
Hi everyone! This issue has been automatically closed due to inactivity. |

Request for modifiers to be able return a value. Specifically, this allows modifiers to be used on functions which have return codes.
The text was updated successfully, but these errors were encountered: