Skip to content

Commit 24e65a4

Browse files
committed
go/analysis/passes/loopclosure: avoid panic in new parallel subtest check when t.Run has single argument
1 parent 9ff31a5 commit 24e65a4

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

go/analysis/passes/loopclosure/loopclosure.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,11 @@ func parallelSubtest(info *types.Info, call *ast.CallExpr) []ast.Stmt {
303303
return nil
304304
}
305305

306+
if len(call.Args) != 2 {
307+
// Ignore calls such as t.Run(fn()).
308+
return nil
309+
}
310+
306311
lit, _ := call.Args[1].(*ast.FuncLit)
307312
if lit == nil {
308313
return nil

go/analysis/passes/loopclosure/testdata/src/subtests/subtest.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,10 @@ func _(t *testing.T) {
140140
t.Parallel()
141141
println(test) // want "loop variable test captured by func literal"
142142
})
143+
144+
// Check that we do not have problems when t.Run has a single argument.
145+
fn := func() (string, func(t *testing.T)) { return "", nil }
146+
t.Run(fn())
143147
}
144148
}
145149

0 commit comments

Comments
 (0)