nelsam / hel

Hel rules over Helheim, where the souls unworthy of Valhalla reside. It's also a mock generator for Go.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Fix Types Which Return Directional Channels

nelsam opened this issue · comments

Given:

type Foo interface {
    Foo() (<-chan struct{})
}

The generated type looks like:

type mockFoo struct {
    FooOutput struct {
        ret0 chan<- chan struct{}
    }
}

This could be an upstream issue with goimports/gofmt, or it could be that making a chan of directional chans isn't supported.

Turns out this is a little more insidious than I initially thought. There is no way without named types to create a channel of receive-only channels.

The fix will be to remove channel directions from function parameters and returns before generating types and constructors. [edit] NOPE! This won't work for input, where the parameter is a receive-only (or send-only) channel, but the channel it's being sent to requires a bi-directional channel.