Skip to content

Clairfy the rule around the use of return in do-blocks #21

@omus

Description

@omus

The return keyword should always be omitted from return statements within short-form method definitions (f(...) = ...). The return keyword should never be omitted from return statements within any other context (function ... end, macro ... end, etc.).

I think it would be good to clarify/revisit the use of return statements in do-blocks. Although do-blocks are just functions there are used commonly like if if/let/begin blocks where the last sub-expression returned.

A particularly annoying example of requiring return statements in do-blocks can be found when working with sprint:

msg = sprint() do io
    Base.showerror(io, e)
    Base.show_backtrace(io, catch_backtrace())
    println(io)
    return nothing
end

Excluding the return statement reduces confusion where someone might think that msg would be assigned to nothing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions