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

Import shadowing breaks generated code #170

Open
blampe opened this issue Mar 27, 2024 · 1 comment · May be fixed by #195
Open

Import shadowing breaks generated code #170

blampe opened this issue Mar 27, 2024 · 1 comment · May be fixed by #195
Labels
bug Something isn't working

Comments

@blampe
Copy link

blampe commented Mar 27, 2024

Actual behavior

Generated code doesn't take into account whether a function parameter might shadow an imported package name.

Expected behavior

The generated code should use imported package names or aliases which don't conflict with parameters. Parameter names should ideally remain the same since they are user-facing.

To Reproduce

// apiclient.go
package foo

import "github.com/docker/docker/client"

type APIClient interface {
	client.APIClient
}
go run go.uber.org/mock/mockgen -typed -package foo -source apiclient.go -destination mockapiclient.go --self_package <...>/foo

The generated code produces functions like this (note the container string argument):

// ContainerDiff mocks base method.
func (m *MockAPIClient) ContainerDiff(ctx context.Context, container string) ([]container.FilesystemChange, error) {
    m.ctrl.T.Helper()
    ret := m.ctrl.Call(m, "ContainerDiff", ctx, container)
    ret0, _ := ret[0].([]container.FilesystemChange)         // <----- error
    ret1, _ := ret[1].(error)
    return ret0, ret1
}

[compiler NotAType] [E] container.FilesystemChange is not a type

Additional Information

  • gomock mode (reflect or source): source
  • gomock version or git ref: 0.4.0
  • golang version: go1.22.1 darwin/arm64

Triage Notes for the Maintainers

@peats-bond
Copy link

same @blampe

@JacobOaks JacobOaks added the bug Something isn't working label Apr 2, 2024
@eyasy1217 eyasy1217 linked a pull request Jul 11, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants