hexdigest / gowrap

GoWrap is a command line tool for generating decorators for Go interfaces
MIT License
1.06k stars 82 forks source link

Allow overlapping methods #50

Closed Saku2 closed 2 years ago

Saku2 commented 2 years ago

Since golang allows overlapping methods in embedded interfaces, do not fail if overlapping methods are found when merging embedded interfaces.

This will unfortunately pull Doc and Comment fields from an arbitrary overlapping method, but in my opinion that's better than returning an error.

hexdigest commented 2 years ago

Hey @Saku2 ,

I like your idea, but I think if we go this way we have to get rid of uncertainty that you mentioned.

Currently mergeMethods is called in one place only: https://github.com/Saku2/gowrap/blob/1f109acb780b5a64032f545e9da671c9b5fe84fd/generator/generator.go#L374

If the embedded interface listed after the method of a container interface it always wins, which isn't correct and as you mentioned and results in the wrong doc/comment/field names.

Can you please do it in two steps in generator.go, so that first we find embedded interfaces and populate methods list from the embedded interface, and only then we process methods of the outer interface?

Saku2 commented 2 years ago

Yeah, makes sense. It should work that way now

hexdigest commented 2 years ago

Thanks @Saku2 ! Released your changes in v1.2.4