title: golang how to access promoted type
body: <p>I have a 'common' structure promoted within two specific structures. For example:</p>
  <pre><code>type common struct {
      name string
  }
  
  type apple struct {
      common
  }
  
  type orange struct {
      common
  }
  </code></pre>
  <p>Details specific to <code>apple</code> and <code>orange</code> are omitted.</p>
  <p>I have a type-specific map of each, e.g., <code>map[string]*apple</code> and <code>map[string]*orange</code>.</p>
  <p>I am trying to make a single function that can extract the <code>common</code> pointers. From what I've tried so far, reflection appears required.</p>
  <p>My function is:</p>
  <pre><code>func getFruitArray(theMap interface{}) []*common {
      m := reflect.ValueOf(theMap)
      cf := make([]*common, 0, m.Len())
      for _, mk := range m.MapKeys() {
          v := m.MapIndex(mk)
          cf = append(cf, v.Interface().(*common))
      }
  
      return cf
  }
  </code></pre>
  <p>This function fails at <code>cf = append(cf, v.Interface().(*common))</code> with:</p>
  <p><code>panic: interface conversion: interface {} is *main.apple, not *main.common</code></p>
  <p>Is there a way to access the promoted struct <code>common</code> without specifically referencing <code>apple</code> or <code>orange</code> in this function?</p>
  <p><a href="https://go.dev/play/p/eDbpD2e58de" rel="nofollow noreferrer">playground example</a></p>