Skip to content

Commit

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

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

Should fix bazel-contrib#3211 (and probably bazel-contrib#3164 as well).
  • Loading branch information
farhaven committed Jun 22, 2022
1 parent 52a7c74 commit 64bf611
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
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ go_source(
"env.go",
"flags.go",
"nogo_main.go",
"nogo_typeparams_go118.go",
"nogo_typeparams_go117.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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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 64bf611

Please sign in to comment.