New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
go/types: fails to fully collect methods from embedded interfaces #22701
Comments
0d18875 is the specific cause of the issue of me not being able to run tests (previously There appears to be something unholy happening when there are internal packages involved, or somehow there is an issue with the init order in go/types, or that there are way too many declarations after walking the nodes. (1 I wrote a small program to print out what it sees: var archSizes = types.SizesFor("gc", build.Default.GOARCH)
func check(pkgName string, fileset *token.FileSet, files []*ast.File) {
var errs []error
config := types.Config{
Importer: importer.Default(),
Error: func(err error) {
errs = append(errs, err)
},
Sizes: archSizes,
}
defs := make(map[*ast.Ident]types.Object)
uses := make(map[*ast.Ident]types.Object)
selectors := make(map[*ast.SelectorExpr]*types.Selection)
typs := make(map[ast.Expr]types.TypeAndValue)
implicits := make(map[ast.Node]types.Object)
info := &types.Info{
Selections: selectors,
Types: typs,
Defs: defs,
Uses: uses,
Implicits: implicits,
}
_, err := config.Check(pkgName, fileset, files, info)
log.Printf("ERROR %v", err)
// inspection
var buf bytes.Buffer
fmt.Fprintf(&buf, "Types:\n")
for n, o := range info.Types {
if id, ok := n.(*ast.Ident); ok && o.IsType() {
// if id.Name == "View" {
// if id.Name == "Cloner" {
if id.Name == "Tensor" {
fmt.Fprintf(&buf, "%v (%v, %v)\n", id.Name, id.NamePos, id.End())
fmt.Fprintf(&buf, "UNDERLYING %v\n", o.Type.Underlying())
}
}
}
log.Println(buf.String())
} I get the correct results (formatted nicely for github):
Perhaps a clue is that the LMK if I can furnish with more information |
OK, so I've figured out as much: Order of declaration matters (which in all practical sense in a multi-file program, is something you can't control). Here's the reproduction
Both program compiles AND runs as expected. The difference is the location of type Aaaer interface {
Aaa(a, b Foo) Foo
} When it's declared after everything has been declared, and when
Therefore it works. But in the case where it doesn't work, here's the sequence of typechecking:
this causes an error |
Thanks. Here is another reproduction.
|
Most likely a duplicate of #18395. |
Confirmed duplicate of #18395 by running with https://go-review.googlesource.com/c/go/+/78955 in debug mode. |
What version of Go are you using (
go version
)?Master branch (14th Nov 2017)
Does this issue reproduce with the latest release?
No. It works fine in Go 1.9
What operating system and processor architecture are you using (
go env
)?What did you do?
Tried to run tests for
gorgonia/tensor
: https://github.com/gorgonia/tensor (go get gorgonia.org/tensor
)MINIMAL REPRODUCTION HERE
After some hours of debugging it seems order of declaration matters:
go vet
works: https://play.golang.org/p/EJp98n8rpugo vet
returns error: https://play.golang.org/p/Lb7GkXYBDTWhat did you expect to see?
The tests run.
What did you see instead?
vet: typecheck failures
Here's a sample line:
But here's the definitions:
View:
Tensor:
Cloner:
Guru does not see the
Cloner
interface:But Guru sees the
Cloner
interface inTensor
:What I've Done:
I'm currently trying to replicate this, but I can't seem to find a replication in a separate file. Any ideas?
The text was updated successfully, but these errors were encountered: