diff --git a/src/cmd/compile/internal/deadcode/deadcode.go b/src/cmd/compile/internal/deadcode/deadcode.go index 65a48b6803..c37a5a6990 100644 --- a/src/cmd/compile/internal/deadcode/deadcode.go +++ b/src/cmd/compile/internal/deadcode/deadcode.go @@ -163,4 +163,5 @@ func markHiddenClosureDead(n ir.Node) { if clo.Func.IsHiddenClosure() { clo.Func.SetIsDeadcodeClosure(true) } + ir.VisitList(clo.Func.Body, markHiddenClosureDead) } diff --git a/test/fixedbugs/issue51839.go b/test/fixedbugs/issue51839.go new file mode 100644 index 0000000000..c3c18915b4 --- /dev/null +++ b/test/fixedbugs/issue51839.go @@ -0,0 +1,22 @@ +// compile + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func main() { + testRecover() + +} + +func testRecover() { + if false { + func() { + defer func() { + _ = recover() + }() + }() + } +}