Skip to content

Commit

Permalink
nogo: instantiate type info for generic types when running under Go >…
Browse files Browse the repository at this point in the history
…=1.18

This mirrors what golang.org/x/tools/go/packages does when loading packages.

Should fix bazelbuild#3211 (and probably bazelbuild#3164 as well).
  • Loading branch information
farhaven committed Jul 18, 2022
1 parent ed56d7e commit f0fd718
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 0 deletions.
2 changes: 2 additions & 0 deletions go/tools/builders/BUILD.bazel
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions go/tools/builders/nogo_main.go
Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions 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) {}
28 changes: 28 additions & 0 deletions 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)
}

0 comments on commit f0fd718

Please sign in to comment.