golang / mock

GoMock is a mocking framework for the Go programming language.
Apache License 2.0
9.28k stars 610 forks source link

Source mode works not correct with different local import aliasing #587

Closed TheZeroSlave closed 2 years ago

TheZeroSlave commented 2 years ago

Actual behavior Generate mock for interface having embedded interface from another package leads to Loading input failed: /Users/desotnikov/go/src/reproduceMockErr/package1/stub.go:6:13: failed parsing returns: /Users/.../go/src/reproduceMockErr/package1/stub.go:6:16: unknown package "model

Expected behavior No error occured

To Reproduce the following structure of project causes error model/model.go

package package2

import "reproduceMockErr/package1"

type SportCar interface {
    package1.Car
    package1.Stub
}

package1/car.go

package package1

import engineData "reproduceMockErr/model"

type Car interface {
    Engine() engineData.EngineData
}

package1/stub.go

package package1

import "reproduceMockErr/model"

type Stub interface {
    EngineData2() model.EngineData
}

package2/sport.go

package package2

import "reproduceMockErr/package1"

type SportCar interface {
    package1.Car
    package1.Stub
}

run: mockgen -source package2/sport.go

Root cause as i mentioned in PR at ast library. It handles import deduplication in a wrong manner(not taking into account local aliasing).

Additional Information

Triage Notes for the Maintainers PR trying to fix that: https://github.com/golang/mock/pull/586

TheZeroSlave commented 2 years ago

@codyoss hi. any news?

codyoss commented 2 years ago

Would you mind creating a small repo to show this. Or else maybe there are typos are the example above is incomplete. I could not reproduce as is.

codyoss commented 2 years ago

Closing due to lack of response.