-
-
Notifications
You must be signed in to change notification settings - Fork 128
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
Fix: add imports for Named Type its Instance Types #199
Fix: add imports for Named Type its Instance Types #199
Conversation
Expected error message in the Not sure why the error is |
```
╭─timvosch@XPS15-ARCH ~/src/moq ‹373b8f9›
╰─➤ docker run --rm -it -v `pwd`:/project --workdir /project golang:1.19 go test ./...
go: downloading github.com/pmezard/go-difflib v1.0.0
go: downloading golang.org/x/tools v0.3.0
go: downloading golang.org/x/mod v0.7.0
go: downloading golang.org/x/sys v0.2.0
? github.com/matryer/moq [no test files]
ok github.com/matryer/moq/example 0.001s [no tests to run]
? github.com/matryer/moq/generate [no test files]
? github.com/matryer/moq/internal/registry [no test files]
ok github.com/matryer/moq/internal/template 0.001s
--- FAIL: TestGoGenerateVendoredPackages (0.00s)
moq_test.go:629: Wait: exit status 1
--- FAIL: TestParseError (0.01s)
moq_test.go:663: unexpected error: couldn't load source package: err: exit status 1: stderr: go build github.com/matryer/notexist: service.go:3:8: cannot find package "." in:
/project/pkg/moq/testpackages/vendor/github.com/matryer/notexist
FAIL
FAIL github.com/matryer/moq/pkg/moq 6.336s
FAIL
```
Edit: Actually installing the
Specifically version 1.19.10 does not work. All minor revisions below that work. Since it was released just two weeks ago, that is why it probably wasn't picked up earlier. I am going through the changelog to see why. I expected the error message just changed and the test needs an update.
Edit 2: Between go 1.19.9 and 1.19.10 the following change happened. I expect that the test should expect a build error instead of the import error, but only for go 1.19.10. diff --git a/src/cmd/go/internal/work/exec.go b/src/cmd/go/internal/work/exec.go
index c24d210711..567f045922 100644
--- a/src/cmd/go/internal/work/exec.go
+++ b/src/cmd/go/internal/work/exec.go
@@ -528,6 +528,12 @@ func (b *Builder) build(ctx context.Context, a *Action) (err error) {
b.Print(a.Package.ImportPath + "\n")
}
+ if p.Error != nil {
+ // Don't try to build anything for packages with errors. There may be a
+ // problem with the inputs that makes the package unsafe to build.
+ return p.Error
+ }
+
if a.Package.BinaryOnly {
p.Stale = true
p.StaleReason = "binary-only packages are no longer supported" @sudo-suhas I am unsure what to do with this, do you have an idea? |
We can add an additional clause for the error string check to cover errors from both Go 1.18 and Go 1.19. |
I updated the test to also check for |
This change has been released in |
Fixes missing imports and package prefixing to generic types. See #177
In the following example a method must be mocked which has a return parameter that has a generic type:
otherpackage.Foo
.Currently mocking
IFooBar
will result in a missingotherpackage
import and the package prefix toFoo
. Note:FoobarFunc: func() GenericBar[Foo]
instead ofFoobarFunc: func() GenericBar[otherpackage.Foo]
.This happens because of an invalid key lookup here, which returns an empty string
""
: internal/registry/var.goThis is fixed by checking if a Named Type has type arguments, and populating imports for those types.
internal/registry/method_scope.go
A new golden test was added for this specific case.
Closes #177
Closes #190