-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
internal/refactor/inline: elide redundant braces
When replacing a CallExpr beneath an ExprStmt, a reduction strategy may return a BlockStmt containing zero or more statements. This change eliminates the braces for the block when it is safe to do so, in other words when these three conditions are met: (a) the parent of the ExprStmt is an unrestricted statement context e.g. a block or the body of a case of a switch or select, but not, say "if f(); cond {". (b) there are no forward gotos in the caller that may jump across a declaration. (Currently we check for any control labels at all in the caller.) (c) there are no conflicts between names declared in the callee block and in the caller block. Plus tests. Also, a fix and test for a latent bug allowing reduction in a restricted "if stmt; expr" context. Fixes golang/go#63259 Change-Id: I558c75d8306dfd0679768cb4b3dbf05f14b23c39 Reviewed-on: https://go-review.googlesource.com/c/tools/+/532099 LUCI-TryBot-Result: Go LUCI <[email protected]> Auto-Submit: Alan Donovan <[email protected]> Reviewed-by: Robert Findley <[email protected]>
- Loading branch information
Showing
7 changed files
with
322 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.