Skip to content

Commit

Permalink
cmd/compile: mark closures made for generic function expressions as w…
Browse files Browse the repository at this point in the history
…rappers

Fixes golang#52237

Change-Id: I7488020c8d157e069202017a293d18230e3aef0d
Reviewed-on: https://go-review.googlesource.com/c/go/+/408876
Reviewed-by: Cherry Mui <[email protected]>
TryBot-Result: Gopher Robot <[email protected]>
Run-TryBot: Keith Randall <[email protected]>
Reviewed-by: Keith Randall <[email protected]>
  • Loading branch information
randall77 committed May 26, 2022
1 parent ec92580 commit dbf5220
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/cmd/compile/internal/noder/stencil.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ func (g *genInst) buildClosure(outer *ir.Func, x ir.Node) ir.Node {

// Make a new internal function.
fn, formalParams, formalResults := startClosure(pos, outer, typ)
fn.SetWrapper(true) // See issue 52237

// This is the dictionary we want to use.
// It may be a constant, it may be the outer functions's dictionary, or it may be
Expand Down
22 changes: 12 additions & 10 deletions src/testing/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,22 @@ func TestTBHelper(t *T) {

want := `--- FAIL: Test (?s)
helperfuncs_test.go:12: 0
helperfuncs_test.go:33: 1
helperfuncs_test.go:40: 1
helperfuncs_test.go:21: 2
helperfuncs_test.go:35: 3
helperfuncs_test.go:42: 4
helperfuncs_test.go:42: 3
helperfuncs_test.go:49: 4
--- FAIL: Test/sub (?s)
helperfuncs_test.go:45: 5
helperfuncs_test.go:52: 5
helperfuncs_test.go:21: 6
helperfuncs_test.go:44: 7
helperfuncs_test.go:56: 8
helperfuncs_test.go:51: 7
helperfuncs_test.go:63: 8
--- FAIL: Test/sub2 (?s)
helperfuncs_test.go:71: 11
helperfuncs_test.go:75: recover 12
helperfuncs_test.go:64: 9
helperfuncs_test.go:60: 10
helperfuncs_test.go:78: 11
helperfuncs_test.go:82: recover 12
helperfuncs_test.go:84: GenericFloat64
helperfuncs_test.go:85: GenericInt
helperfuncs_test.go:71: 9
helperfuncs_test.go:67: 10
`
lines := strings.Split(buf.String(), "\n")
durationRE := regexp.MustCompile(`\(.*\)$`)
Expand Down
10 changes: 10 additions & 0 deletions src/testing/helperfuncs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ func helperCallingHelper(t *T, msg string) {
helper(t, msg)
}

func genericHelper[G any](t *T, msg string) {
t.Helper()
t.Error(msg)
}

var genericIntHelper = genericHelper[int]

func testHelper(t *T) {
// Check combinations of directly and indirectly
// calling helper functions.
Expand Down Expand Up @@ -73,6 +80,9 @@ func testHelper(t *T) {
// Check that helper-ness propagates up through panic/recover.
// See https://golang.org/issue/31154.
recoverHelper(t, "12")

genericHelper[float64](t, "GenericFloat64")
genericIntHelper(t, "GenericInt")
}

func parallelTestHelper(t *T) {
Expand Down

0 comments on commit dbf5220

Please sign in to comment.