@@ -75,7 +75,7 @@ func logicalAndElseBranchAlwaysBad2() {
75
75
if errorSource () == ErrNone && someOtherCondition () {
76
76
doSomething ()
77
77
} else {
78
- // Bad: On error we may enter either branch, but neither one returns .
78
+ // Bad: there is no return statement at all .
79
79
insteadOfReturn ()
80
80
}
81
81
doSomething ()
@@ -85,7 +85,7 @@ func logicalAndElseBranchAlwaysBad2() {
85
85
func logicalAndThenBranchGood () {
86
86
87
87
if someOtherCondition () && errorSource () != ErrNone {
88
- // Good: whenever an error is indicated we return.
88
+ // Good: whenever an error is indicated we return (note errorSource() is not called until someOtherCondition() passes)
89
89
return
90
90
}
91
91
doSomething ()
@@ -95,7 +95,7 @@ func logicalAndThenBranchGood() {
95
95
func logicalAndElseBranchGood () {
96
96
97
97
if someOtherCondition () && errorSource () == ErrNone {
98
- // Good: whenever an error is indicated we return.
98
+ // Good: whenever an error is indicated we return (note errorSource() is not called until someOtherCondition() passes)
99
99
doSomething ()
100
100
} else {
101
101
return
@@ -154,7 +154,7 @@ func logicalOrThenBranchAlwaysBad() {
154
154
func logicalOrThenBranchGood () {
155
155
156
156
if someOtherCondition () || errorSource () != ErrNone {
157
- // Good: whenever an error is indicated we return.
157
+ // Good: whenever an error is indicated we return. (note errorSource() is not called until someOtherCondition() fails)
158
158
return
159
159
}
160
160
doSomething ()
@@ -164,7 +164,7 @@ func logicalOrThenBranchGood() {
164
164
func logicalOrElseBranchGood () {
165
165
166
166
if someOtherCondition () || errorSource () == ErrNone {
167
- // Good: whenever an error is indicated we return.
167
+ // Good: whenever an error is indicated we return. (note errorSource() is not called until someOtherCondition() fails)
168
168
doSomething ()
169
169
} else {
170
170
return
0 commit comments