Skip to content
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

Warn about implicit returns #708

Closed
ethers opened this issue Jul 10, 2016 · 2 comments
Closed

Warn about implicit returns #708

ethers opened this issue Jul 10, 2016 · 2 comments
Labels
closed due inactivity The issue/PR was automatically closed due to inactivity. language design :rage4: Any changes to the language, e.g. new features stale The issue/PR was marked as stale because it has been open for too long.

Comments

@ethers
Copy link
Member

ethers commented Jul 10, 2016

As recent events have shown, we need to make Solidity more difficult to be misused or used in ways that can cause bugs.

Granted the following example is contrived, but we really need to consider if the advantages of returning values implicitly by name is worth it.

    function foo() returns (uint r) {
        r = 1;
        if (somethingComplexThatReturnsFalse()) {
            return 2;
        }
    }

This may be a valid example, and if this feature is really desired, it would still be helpful to explicitly have return somewhere.

    /// @dev Computes the winning proposal taking all
    /// previous votes into account.
    function winningProposal() constant
            returns (uint winningProposal)
    {
        uint winningVoteCount = 0;
        for (uint p = 0; p < proposals.length; p++) {
            if (proposals[p].voteCount > winningVoteCount) {
                winningVoteCount = proposals[p].voteCount;
                winningProposal = p;
            }
        }
    }

My first thought is just to deprecate and remove this feature.
If it's desired, maybe clearer syntax such as [return winningProposal = p;] is possible and can help.
Before we optimize for say features that might save gas, I think we agree to focus first on safety.

@chriseth
Copy link
Contributor

We might add that now that we have tuples.

@chriseth chriseth changed the title Dangers of returning values implicitly by name Warn about implicit returns Jul 14, 2016
@chriseth chriseth added this to the 2-non-breaking-saftey-changes milestone Aug 11, 2016
@axic axic added the language design :rage4: Any changes to the language, e.g. new features label Jul 28, 2018
@axic axic removed this from the 2-non-breaking-saftey-changes milestone Jul 30, 2018
@axic axic removed the accepted label Aug 1, 2018
@NunoFilipeSantos NunoFilipeSantos added the stale The issue/PR was marked as stale because it has been open for too long. label Nov 25, 2022
@github-actions
Copy link

Hi everyone! This issue has been closed due to inactivity.
If you think this issue is still relevant in the latest Solidity version and you have something to contribute, feel free to reopen.
However, unless the issue is a concrete proposal that can be implemented, we recommend starting a language discussion on the forum instead.

@github-actions github-actions bot added the closed due inactivity The issue/PR was automatically closed due to inactivity. label Jan 27, 2023
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Jan 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed due inactivity The issue/PR was automatically closed due to inactivity. language design :rage4: Any changes to the language, e.g. new features stale The issue/PR was marked as stale because it has been open for too long.
Projects
None yet
Development

No branches or pull requests

4 participants