File tree 2 files changed +46
-1
lines changed
analyzer/testdata/src/require-error-skip-logic
2 files changed +46
-1
lines changed Original file line number Diff line number Diff line change @@ -509,6 +509,38 @@ func TestService_DeclareFixedRoles(t *testing.T) {
509
509
}
510
510
}
511
511
512
+ func TestIssue62 (t * testing.T ) {
513
+ cases := []struct {
514
+ name string
515
+ expectedError error
516
+ failureDetails any
517
+ }{
518
+ {},
519
+ }
520
+
521
+ for _ , tc := range cases {
522
+ t .Run (tc .name , func (t * testing.T ) {
523
+ failureDetails , err := operationWithResult ()
524
+
525
+ if tc .expectedError != nil {
526
+ assert .Error (t , err )
527
+ } else {
528
+ require .NoError (t , err )
529
+ if tc .failureDetails != nil {
530
+ assert .Error (t , err ) // want "require-error: for error assertions use require"
531
+ assert .Equal (t , failureDetails , tc .failureDetails )
532
+ } else if false {
533
+ assert .Error (t , err )
534
+ } else if true {
535
+ assert .Error (t , err )
536
+ } else {
537
+ assert .Equal (t , failureDetails , tc .failureDetails )
538
+ }
539
+ }
540
+ })
541
+ }
542
+ }
543
+
512
544
func createTempPackageJson (t * testing.T , version string ) error {
513
545
t .Helper ()
514
546
Original file line number Diff line number Diff line change @@ -176,7 +176,20 @@ func needToSkipBasedOnContext(
176
176
_ , blockEndWithReturn := block .List [len (block .List )- 1 ].(* ast.ReturnStmt )
177
177
if ! blockEndWithReturn {
178
178
for i := currCallIndex + 1 ; i < len (otherCalls ); i ++ {
179
- if (otherCalls [i ].rootIf == nil ) || (otherCalls [i ].rootIf != currCall .rootIf ) {
179
+ nextCall := otherCalls [i ]
180
+ nextCallInElseBlock := false
181
+
182
+ if pIf := currCall .parentIf ; pIf != nil && pIf .Else != nil {
183
+ ast .Inspect (pIf .Else , func (n ast.Node ) bool {
184
+ if n == nextCall .call {
185
+ nextCallInElseBlock = true
186
+ return false
187
+ }
188
+ return true
189
+ })
190
+ }
191
+
192
+ if ! nextCallInElseBlock {
180
193
noCallsAfter = false
181
194
break
182
195
}
You can’t perform that action at this time.
0 commit comments