diff --git a/src/cmd/compile/internal/types2/check_test.go b/src/cmd/compile/internal/types2/check_test.go index 8f537f91209..35bbcec5c58 100644 --- a/src/cmd/compile/internal/types2/check_test.go +++ b/src/cmd/compile/internal/types2/check_test.go @@ -182,7 +182,8 @@ func testFilesImpl(t *testing.T, filenames []string, srcs [][]byte, colDelta uin } if goexperiment != "" { - defer setGOEXPERIMENT(goexperiment)() + revert := setGOEXPERIMENT(goexperiment) + defer revert() } // By default, gotypesalias is not set. @@ -329,9 +330,7 @@ func setGOEXPERIMENT(goexperiment string) func() { } old := buildcfg.Experiment buildcfg.Experiment = *exp - return func() { - buildcfg.Experiment = old - } + return func() { buildcfg.Experiment = old } } // TestManual is for manual testing of a package - either provided diff --git a/src/cmd/compile/internal/types2/object_test.go b/src/cmd/compile/internal/types2/object_test.go index 429f463bf70..955fa351a46 100644 --- a/src/cmd/compile/internal/types2/object_test.go +++ b/src/cmd/compile/internal/types2/object_test.go @@ -115,7 +115,8 @@ func TestObjectString(t *testing.T) { for i, test := range testObjects { t.Run(fmt.Sprint(i), func(t *testing.T) { if test.alias { - defer setGOEXPERIMENT("aliastypeparams")() + revert := setGOEXPERIMENT("aliastypeparams") + defer revert() } src := "package p; " + test.src conf := Config{Error: func(error) {}, Importer: defaultImporter(), EnableAlias: test.alias} diff --git a/src/go/types/check_test.go b/src/go/types/check_test.go index be556169746..a10d0147da2 100644 --- a/src/go/types/check_test.go +++ b/src/go/types/check_test.go @@ -197,7 +197,8 @@ func testFilesImpl(t *testing.T, filenames []string, srcs [][]byte, manual bool, } if goexperiment != "" { - defer setGOEXPERIMENT(goexperiment)() + revert := setGOEXPERIMENT(goexperiment) + defer revert() } // By default, gotypesalias is not set. @@ -357,9 +358,7 @@ func setGOEXPERIMENT(goexperiment string) func() { } old := buildcfg.Experiment buildcfg.Experiment = *exp - return func() { - buildcfg.Experiment = old - } + return func() { buildcfg.Experiment = old } } // TestManual is for manual testing of a package - either provided diff --git a/src/go/types/object_test.go b/src/go/types/object_test.go index 1a3f223e09f..704d4128ba8 100644 --- a/src/go/types/object_test.go +++ b/src/go/types/object_test.go @@ -115,7 +115,8 @@ func TestObjectString(t *testing.T) { for i, test := range testObjects { t.Run(fmt.Sprint(i), func(t *testing.T) { if test.alias { - defer setGOEXPERIMENT("aliastypeparams")() + revert := setGOEXPERIMENT("aliastypeparams") + defer revert() t.Setenv("GODEBUG", "gotypesalias=1") }