You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Actual behavior
If your source file contains dot imports and the output package name is different, mockgen's output will be a file that cannot be compiled.
Expected behavior
The output will be a file that can be compiled successfully.
To Reproduce
The source file internal.go, which contains a dot import, is as follows:
package internal
//go:generate go run go.uber.org/mock/mockgen -source=internal.go -destination=mocks/internal_gen.goimport (
. "context"
)
typeWithDotImportsinterface {
ImportDot() Context
}
Run go generate ./.... This produces the file mocks/internal_gen.go.
In mocks/internal_gen.go, the return type Context of the ImportDot method is incorrectly qualified as internal.Context, even though such qualification is unnecessary.
gomock mode (reflect or source): source (I haven't tried withe reflect, issue might also happen)
gomock version or git ref: v0.4.0
golang version: 1.21.3
Triage Notes for the Maintainers
Dot import are seldom used.
This bug may not be worth fixing.
So how about adding the following code to after this line.
ifpkg.Name!=outputPackageName&&len(pkg.DotImports) >0 {
log.Fatalf("Different package name specifications including dot imports are not yet supported: %v != %v", pkg.Name, outputPackageName)
}
Fundamentally, the issue seems to be that parseType method in mockgen/parse.go does not return the correct package name for dot import types.
The text was updated successfully, but these errors were encountered:
I don't think it's a duplicate because the errors are slightly different.
this issue is an error related to qualification.
138 is about an error with import not used.
Actual behavior
If your source file contains dot imports and the output package name is different, mockgen's output will be a file that cannot be compiled.
Expected behavior
The output will be a file that can be compiled successfully.
To Reproduce
internal.go
, which contains a dot import, is as follows:Run
go generate ./...
. This produces the filemocks/internal_gen.go
.In
mocks/internal_gen.go
, the return typeContext
of theImportDot
method is incorrectly qualified asinternal.Context
, even though such qualification is unnecessary.Additional Information
Triage Notes for the Maintainers
Dot import are seldom used.
This bug may not be worth fixing.
So how about adding the following code to after this line.
Fundamentally, the issue seems to be that
parseType
method inmockgen/parse.go
does not return the correct package name for dot import types.The text was updated successfully, but these errors were encountered: