diff --git a/go/tools/builders/BUILD.bazel b/go/tools/builders/BUILD.bazel index ec45446d1..bb796883e 100644 --- a/go/tools/builders/BUILD.bazel +++ b/go/tools/builders/BUILD.bazel @@ -81,6 +81,8 @@ go_source( "env.go", "flags.go", "nogo_main.go", + "nogo_typeparams_go117.go", + "nogo_typeparams_go118.go", "pack.go", ], # //go/tools/builders:nogo_srcs is considered a different target by diff --git a/go/tools/builders/nogo_main.go b/go/tools/builders/nogo_main.go index 97c683e10..e33b49027 100644 --- a/go/tools/builders/nogo_main.go +++ b/go/tools/builders/nogo_main.go @@ -335,6 +335,9 @@ func load(packagePath string, imp *importer, filenames []string) (*goPackage, er Scopes: make(map[ast.Node]*types.Scope), Selections: make(map[*ast.SelectorExpr]*types.Selection), } + + initInstanceInfo(info) + types, err := config.Check(packagePath, pkg.fset, syntax, info) if err != nil { pkg.illTyped, pkg.typeCheckError = true, err diff --git a/go/tools/builders/nogo_typeparams_go117.go b/go/tools/builders/nogo_typeparams_go117.go new file mode 100644 index 000000000..9b6fe9ac5 --- /dev/null +++ b/go/tools/builders/nogo_typeparams_go117.go @@ -0,0 +1,23 @@ +/* Copyright 2022 The Bazel Authors. All rights reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +//go:build !go1.18 +// +build !go1.18 + +package main + +import "go/types" + +func initInstanceInfo(*types.Info) {} diff --git a/go/tools/builders/nogo_typeparams_go118.go b/go/tools/builders/nogo_typeparams_go118.go new file mode 100644 index 000000000..787b492a2 --- /dev/null +++ b/go/tools/builders/nogo_typeparams_go118.go @@ -0,0 +1,28 @@ +/* Copyright 2022 The Bazel Authors. All rights reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +//go:build go1.18 +// +build go1.18 + +package main + +import ( + "go/ast" + "go/types" +) + +func initInstanceInfo(info *types.Info) { + info.Instances = make(map[*ast.Ident]types.Instance) +}