Skip to content
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

cmd/go: reject adding methods in _test.go file #6204

Closed
remyoudompheng opened this issue Aug 21, 2013 · 10 comments
Closed

cmd/go: reject adding methods in _test.go file #6204

remyoudompheng opened this issue Aug 21, 2013 · 10 comments
Labels
FrozenDueToAge Suggested Issues that may be good for new contributors looking for work to do.
Milestone

Comments

@remyoudompheng
Copy link
Contributor

What steps will reproduce the problem?
1. Extract bug.tar.gz into $GOPATH/src
2. Run "go test p2"

What is the expected output? What do you see instead?

Expected: "PASS"

Instead:

# testmain
/opt/remy/go/pkg/tool/linux_amd64/6l: conflicting definitions for @"p2".Secret
/tmp/go-build276558121/p2/_test/p2_test.a(_go_.6):  type @"p2".Secret struct {
@"p2".field []uint64 }
    func (@"p2".f·2 *@"p2".Secret "esc:0x0") Bits () (? []uint64) { return @"p2".f·2.@"p2".field }
/tmp/go-build276558121/p1.a(_go_.6):    type @"p2".Secret struct {
@"p2".field []uint64 }
FAIL    p2 [build failed]

The example combines:
- a export_test.go to add an exported method to a type for tests
- a p2_test package that depends on p1 which depends on p2.

Attachments:

  1. bug.tar.gz (606 bytes)
@remyoudompheng
Copy link
Contributor Author

Comment 1:

I've encountered this issue with Go 1.0, Go 1.1 (and 1.1.2) and tip.

@rsc
Copy link
Contributor

rsc commented Sep 3, 2013

Comment 2:

This use case is not supported: you cannot add methods in _test.go files.
In Go 1.3 maybe we can build a better error message.

Labels changed: added go1.3, removed go1.2maybe.

@rsc
Copy link
Contributor

rsc commented Dec 4, 2013

Comment 3:

Labels changed: added release-go1.3.

@rsc
Copy link
Contributor

rsc commented Dec 4, 2013

Comment 4:

Labels changed: removed go1.3.

@rsc
Copy link
Contributor

rsc commented Dec 4, 2013

Comment 5:

Labels changed: added repo-main.

@rsc
Copy link
Contributor

rsc commented May 9, 2014

Comment 7:

I have no good ideas about how to diagnose this.

Labels changed: added priority-later, release-none, suggested, removed priority-triage, release-go1.3.

@remyoudompheng remyoudompheng added accepted Suggested Issues that may be good for new contributors looking for work to do. labels May 9, 2014
@rsc rsc added this to the Unplanned milestone Apr 10, 2015
@odeke-em
Copy link
Member

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?

@josharian
Copy link
Contributor

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.

@rsc
Copy link
Contributor

rsc commented Feb 6, 2018

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.

@gopherbot
Copy link

Change https://golang.org/cl/92215 mentions this issue: cmd/go: rebuild as needed for tests of packages that add methods

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge Suggested Issues that may be good for new contributors looking for work to do.
Projects
None yet
Development

No branches or pull requests

5 participants