-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/go: reject adding methods in _test.go file #6204
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
Comments
This issue still exists today $ cat foo.go
package foo
type Foo struct {
}
func (f *Foo) String() string {
return "foo"
}
func (f *Foo) All() string {
return f.String() + f.Name()
}
$ cat foo_test.go
package foo
import (
"testing"
)
func TestFoo(t *testing.T) {
}
func (f *Foo) Name() string {
return "foo:name"
} $ go test -v
=== RUN TestFoo
--- PASS: TestFoo (0.00s)
PASS
ok _/Users/emmanuelodeke/Desktop/openSrc/bugs/golang/6204 0.006s I wonder though if this will be a big breaking change. Some ideas or corpus checks @rsc @ianlancetaylor @broady @bradfitz? |
The easiest way to diagnose this might be in cmd/go, when parsing test packages—use the AST to build a list of all types defined in the package and compare all methods against that list. |
The repro in #23701 is also essentially identical to @remyoudompheng's test case from 2013. (That case started compiling a while back, because we stopped being picky in the linker, but it wasn't necessary compiled correctly.) The fix in #23701 will also fix this case. I didn't fix it in 2013 because it was too hard. The new build cache work makes the fix easy, so I will commit the fix as well as a test, and then we'll have locked in this ability. Even though I might have preferred long ago to reject it out of hand, it does seem too late to do that now. |
Change https://golang.org/cl/92215 mentions this issue: |
Attachments:
The text was updated successfully, but these errors were encountered: