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: new embedded interface behavior (possible regression) #29029
Comments
/cc @griesemer |
I can reproduce this. It does look like a regression. |
Stand-alone reproducer (no need to use loader): https://play.golang.org/p/6rledUr3Mhx |
The loader type-checks the test package by type-checking the _test file incrementally, via a 2nd go/types.Files call. That API is meant to be called like this, but in the process go/types starts with a fresh (internal) interface cache which causes incorrect recomputation of interface methods. The following diff fixes the problem: diff --git a/src/go/types/check.go b/src/go/types/check.go
index 91df94dcbc..10e8c500ac 100644
--- a/src/go/types/check.go
+++ b/src/go/types/check.go
@@ -192,7 +192,7 @@ func (check *Checker) initFiles(files []*ast.File) {
check.firstErr = nil
check.methods = nil
- check.interfaces = nil
+ // check.interfaces = nil
check.untyped = nil
check.delayed = nil We should definitively do this since adding (test) files to a package cannot change any of the already computed interfaces (even though it may add methods to concrete types). So this is a useful optimization in its own right. That said, it's unclear yet why it's also necessary. |
Change https://golang.org/cl/152259 mentions this issue: |
See comments in CL as to why the suggested diff is correct and also necessary. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I type-checked and printed definitions from a package with a test file that embeds a non-test interface into another interface.
What did you expect to see?
The interface method with the correct receiver type:
What did you see instead?
The receiver type was overwritten based the contents of the test file:
Demo project
Check out this program: https://github.com/ccbrown/go-interface-method-type-bug
Run
go run main.go
. With Go 1.10, you get the output I would expect. With Go 1.11, you get different output.This makes tooling such as @dominikh's unused tool break in Go 1.11 for certain cases where tests define interfaces that embed other interfaces.
The text was updated successfully, but these errors were encountered: