Skip to content

Commit

Permalink
internal/typeparams: hide go1.18 API usage behind a build constraint
Browse files Browse the repository at this point in the history
Temporarily hide usage of the new go/types API, so that we can safely
tag x/[email protected] without risk of further breakage when these APIs
change.

Updates golang/go#48632

Change-Id: Idba02d09644622b3d973a684a76514c86eefa17f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/352854
Trust: Robert Findley <[email protected]>
Run-TryBot: Robert Findley <[email protected]>
Reviewed-by: Rebecca Stambler <[email protected]>
gopls-CI: kokoro <[email protected]>
TryBot-Result: Go Bot <[email protected]>
  • Loading branch information
findleyr committed Sep 28, 2021
1 parent 7898fe6 commit 0df0ca0
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 18 deletions.
7 changes: 7 additions & 0 deletions go/internal/gcimporter/gcimporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"time"

"golang.org/x/tools/internal/testenv"
"golang.org/x/tools/internal/typeparams"
)

func TestMain(m *testing.M) {
Expand Down Expand Up @@ -106,6 +107,12 @@ func testDir(t *testing.T, dir string, endTime time.Time) (nimports int) {
for _, ext := range pkgExts {
if strings.HasSuffix(f.Name(), ext) {
name := f.Name()[0 : len(f.Name())-len(ext)] // remove extension
if testenv.UsesGenerics(name) && !typeparams.Enabled {
// golang/go#48632: Skip generic packages when type parameters are
// not enabled, as a temporary measure to allow avoiding the new
// go/types API on Go 1.18.
continue
}
if testPath(t, filepath.Join(dir, name), dir) != nil {
nimports++
}
Expand Down
4 changes: 2 additions & 2 deletions go/internal/gcimporter/iexport_go118_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build go1.18
// +build go1.18
//go:build typeparams && go1.18
// +build typeparams,go1.18

package gcimporter_test

Expand Down
8 changes: 6 additions & 2 deletions go/internal/gcimporter/iexport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"golang.org/x/tools/go/internal/gcimporter"
"golang.org/x/tools/go/loader"
"golang.org/x/tools/internal/testenv"
"golang.org/x/tools/internal/typeparams"
)

func readExportFile(filename string) ([]byte, error) {
Expand Down Expand Up @@ -96,9 +97,12 @@ func TestIExportData_stdlib(t *testing.T) {
// TODO(#48595): fix this test with GOEXPERIMENT=unified.
isUnified := isUnifiedBuilder()
for _, path := range buildutil.AllPackages(conf.Build) {
if !(isUnified && testenv.UsesGenerics(path)) {
conf.Import(path)
if testenv.UsesGenerics(path) && (isUnified || !typeparams.Enabled) {
// golang/go#48632: Skip generic packages if we can't handle type
// parameters.
continue
}
conf.Import(path)
}

// Create a package containing type and value errors to ensure
Expand Down
4 changes: 2 additions & 2 deletions go/internal/gcimporter/support_go117.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build !go1.18
// +build !go1.18
//go:build !typeparams || !go1.18
// +build !typeparams !go1.18

package gcimporter

Expand Down
4 changes: 2 additions & 2 deletions go/internal/gcimporter/support_go118.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build go1.18
// +build go1.18
//go:build typeparams && go1.18
// +build typeparams,go1.18

package gcimporter

Expand Down
4 changes: 2 additions & 2 deletions internal/typeparams/enabled_go117.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build !go1.18
// +build !go1.18
//go:build !typeparams || !go1.18
// +build !typeparams !go1.18

package typeparams

Expand Down
4 changes: 2 additions & 2 deletions internal/typeparams/enabled_go118.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build go1.18
// +build go1.18
//go:build typeparams && go1.18
// +build typeparams,go1.18

package typeparams

Expand Down
4 changes: 2 additions & 2 deletions internal/typeparams/typeparams_go117.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build !go1.18
// +build !go1.18
//go:build !typeparams || !go1.18
// +build !typeparams !go1.18

package typeparams

Expand Down
4 changes: 2 additions & 2 deletions internal/typeparams/typeparams_go118.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build go1.18
// +build go1.18
//go:build typeparams && go1.18
// +build typeparams,go1.18

package typeparams

Expand Down
4 changes: 2 additions & 2 deletions internal/typeparams/typeparams_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build go1.18
// +build go1.18
//go:build typeparams && go1.18
// +build typeparams,go1.18

package typeparams_test

Expand Down

0 comments on commit 0df0ca0

Please sign in to comment.