From 0244bed0333885b7b399107ad4e8157c54b5c3b2 Mon Sep 17 00:00:00 2001 From: Damian Gryski Date: Tue, 11 Apr 2023 08:18:18 -0700 Subject: [PATCH] testdata: add test for else/defer bug --- testdata/calls.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/testdata/calls.go b/testdata/calls.go index b8b10c2c..96044395 100644 --- a/testdata/calls.go +++ b/testdata/calls.go @@ -82,6 +82,10 @@ func main() { // covered the entire variable. var x issue1304 x.call() + + if testDeferElse(false) != 0 { + println("else defer returned wrong value") + } } func runFunc(f func(int), arg int) { @@ -232,3 +236,15 @@ func (x issue1304) call() { type recursiveFuncType func(recursiveFuncType) var recursiveFunction recursiveFuncType + +//go:noinline +func testDeferElse(b bool) (r int) { + if !b { + defer func() { + r = 0 + + }() + } + + return 1 +}