Dug a bit further. The way our build works (debian build which copies files into a build area) meant that 'go vet' was running on the files in 2 different locations. All worked fine in the build area, but in the source area, it was generating the spurious 'undefined method' error. By filtering out the source area directories from the directories I ran go vet on, the problem is resolved.
William On Tuesday, 31 August 2021 at 08:25:35 UTC+1 wji...@gmail.com wrote: > Hmm ... obviously not as simple a problem as I first thought. I'll need to > start with the definitely failing code and reduce it to as simple a case as > possible that still exhibits the problem. Had (wrongly) assumed it would > happen in all cases hence the simple example given initially. > > On Friday, 27 August 2021 at 11:22:42 UTC+1 seank...@gmail.com wrote: > >> I can't reproduce the error you're seeing either in 1.15 or in later >> versions with the code you provided >> >> On Friday, August 27, 2021 at 10:11:07 AM UTC+2 wji...@gmail.com wrote: >> >>> Hi, >>> >>> We've recently moved from using 'go tool vet' to 'go vet' (we need to >>> stick to the Go versions shipped with Debian) and have found that it is not >>> finding public methods that we export for test only by putting them in >>> _test.go files (error is 'undeclared name'). Disable go vet, and you can >>> build and run the test code fine. Problematic code is something like this: >>> >>> export_for_test.go: >>> >>> package foo >>> >>> func ExportedForTest() { >>> // Do something >>> } >>> >>> --- >>> >>> foo_test.go >>> >>> package foo_test >>> >>> import ( >>> "foo" >>> "testing" >>> ) >>> >>> func TestFoo(t *testing.T) { >>> foo.ExportedForTest() >>> } >>> >>> --- >>> >>> We are using Go 1.15 in Debian 10. >>> >>> This would appear to be a bug in 'go vet' given the actual build and >>> running of test code works fine. Is there any way to work around this, and >>> has it been fixed in more recent releases (not that this would solve our >>> problem as we are stuck with the buster-backport version of Go for now, and >>> Debian 11 is also using Go 1.15). >>> >>> Thanks, >>> >>> William >>> >>> >>> -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/8f9789b1-e5e9-45ff-b0bd-5ff12a9964c9n%40googlegroups.com.