Commit 6c6ad08e authored by Josh Bleecher Snyder's avatar Josh Bleecher Snyder

go/types: fix bad variable shadowing in offsetsof

Introduced in CL 26995.

Fixes #16902

Change-Id: I8e749f598167e1f8b82cd5e735a7eb5291362e5e
Reviewed-on: https://go-review.googlesource.com/28070
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarRobert Griesemer <gri@golang.org>
parent 67ea7107
......@@ -167,7 +167,7 @@ func (conf *Config) offsetsof(T *Struct) []int64 {
if T.NumFields() > 0 {
// compute offsets on demand
if s := conf.Sizes; s != nil {
offsets := s.Offsetsof(T.fields)
offsets = s.Offsetsof(T.fields)
// sanity checks
if len(offsets) != T.NumFields() {
panic("Config.Sizes.Offsetsof returned the wrong number of offsets")
......
......@@ -8,6 +8,7 @@ package types_test
import (
"go/ast"
"go/importer"
"go/parser"
"go/token"
"go/types"
......@@ -81,3 +82,31 @@ var s struct {
t.Errorf("OffsetsOf(%v) = %v want %v", ts, offsets, []int{0, 4})
}
}
func TestIssue16902(t *testing.T) {
const src = `
package a
import "unsafe"
const _ = unsafe.Offsetof(struct{ x int64 }{}.x)
`
fset := token.NewFileSet()
f, err := parser.ParseFile(fset, "x.go", src, 0)
if err != nil {
t.Fatal(err)
}
info := types.Info{Types: make(map[ast.Expr]types.TypeAndValue)}
conf := types.Config{
Importer: importer.Default(),
Sizes: &types.StdSizes{WordSize: 8, MaxAlign: 8},
}
_, err = conf.Check("x", fset, []*ast.File{f}, &info)
if err != nil {
t.Fatal(err)
}
for _, tv := range info.Types {
_ = conf.Sizes.Sizeof(tv.Type)
_ = conf.Sizes.Alignof(tv.Type)
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment