title: Returning interfaces for nested structs
body: <p>I'm trying to break circular dependencies in a reasonably sized golang project by using interfaces. I have some nested structs like this:</p>
  
  <pre><code>// these are in one package...
  type config struct {
      region string
  }
  
  type system struct {
      name string
      config config
  }
  
  func (s system) getName() string {
      return s.name
  }
  
  func (s system) getConfig() config {
      return s.config
  }
  
  func (c config) getRegion() string {
      return c.region
  }
  </code></pre>
  
  <p>And in another package that wants to use them I'm declaring some corresponding nested interfaces:</p>
  
  <pre><code>type iConfig interface {
      getRegion() string
  }
  
  type iSystem interface {
      getName() string
      getConfig() iConfig
  }
  
  // and has functions like
  func New(system iSystem) {
      fmt.Printf("region=%s", system.getConfig().getRegion())
  }
  </code></pre>
  
  <p>But when I try to use them like this:</p>
  
  <pre><code>theSystem := system{
      name: "testName",
      config:config{
          region:"testRegion",
      },
  }
  
  New(theSystem)      // doesn't work
  </code></pre>
  
  <p>I get an error:</p>
  
  <pre><code>cannot use theSystem (type system) as type iSystem in argument to New:
  system does not implement iSystem (wrong type for getConfig method)
      have getConfig() config
      want getConfig() iConfig
  </code></pre>
  
  <p>It seems that because my concrete <code>system</code> struct returns a concrete type <code>config</code> Go doesn't think it satisifes the <code>iConfig</code> interface - even though  I can use <code>config</code> via the <code>iConfig</code> interface directly. I was expecting <code>config</code> to implicitly satisfy the <code>iConfig</code> interface but that's not happening. How can I fix this?</p>
  
  <p>Here's a link to the <a href="https://play.golang.org/p/MjLwEY4ZBTi" rel="nofollow noreferrer">Go Playground</a>.</p>