rjeczalik / interfaces

Code generation tools for Go.
MIT License
420 stars 31 forks source link

Generating an interface in the same package as the implementation is broken #44

Open stgraham2000 opened 9 months ago

stgraham2000 commented 9 months ago

Currently if you want to generate an interface file and have it reside in the same package as things the interface might depend on then you end up with generated code that fails to compile because the code is trying to import itself.

For instance, you have a package called car and you have defined a type car.Tire in the car package. You also have a service implementation file like car.Car and you have a method like ChangeTire(tire Tire). You now want to create an interface file in the same package car and call this interface file intf.go. If you try to generate the interface for car.Car you will have an extra import to the car package and your interface will have the method ChangeTire(tire car.Tire). This will fail to compile.

I expect the interface file to not have the extra import and the method should be ChangeTire(tire Tire).