-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from RalfJung/nested-early-return
better handling of nested conditionals that early return
- Loading branch information
Showing
7 changed files
with
70 additions
and
18 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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package example | ||
|
||
func Skip() {} | ||
|
||
func BadIf(i uint64) { | ||
if i == 0 { | ||
return | ||
} else { // ERROR else with early return | ||
Skip() | ||
} | ||
Skip() | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package example | ||
|
||
func Skip() {} | ||
|
||
func BadIf2(i uint64) { | ||
if i == 0 { | ||
if true { | ||
return // ERROR nested if statement branches differ on whether they return | ||
} else { | ||
Skip() | ||
} | ||
} | ||
Skip() | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
package example | ||
|
||
func Skip() {} | ||
func Skip() bool { return false } | ||
|
||
func BadLoop(i uint64) { | ||
if i == 0 { | ||
return | ||
} else { // ERROR else with early return | ||
Skip() | ||
// This used to translate incorrectly, into a loop that always `Continue`s. | ||
for { | ||
if !Skip() { // ERROR nested if statement branches differ on whether they return | ||
break | ||
} | ||
} | ||
Skip() | ||
} |