title: golang type conversion not working as (I) expected
body: <p>I'm using <a href="https://github.com/jessevdk/go-flags" rel="nofollow noreferrer">go-flags</a> to parse command line options.</p>
  <p>Per the go-flags docs:</p>
  <blockquote>
  <p>... [if] either -h or --help was specified in the command line
  arguments, a help message will be automatically printed. Furthermore,
  the special error type ErrHelp is returned.</p>
  </blockquote>
  <p>The method I'm calling is:</p>
  <pre><code>func (p *Parser) Parse() ([]string, error) {
  </code></pre>
  <p>I'm calling it with:</p>
  <pre><code>var opts struct {
      // ...
  }
  
  func main() {
  
      parser := flags.NewParser(&amp;opts, flags.Default)
  
      args, err := parser.Parse()
  </code></pre>
  <p>A snippet from the file that defines ErrHelp looks like this:</p>
  <pre><code>type ErrorType uint
  
  const (
      // Unknown or generic error
      ErrUnknown ErrorType = iota
  
      // Expected an argument but got none
      ErrExpectedArgument
  
      // ...
  
      // The error contains the builtin help message
      ErrHelp
  
      // ...
  )
  
  // Error represents a parser error. The error returned from Parse is of this
  // type. The error contains both a Type and Message.
  type Error struct {
      // The type of error
      Type ErrorType
  
      // The error message
      Message string
  }
  
  // Get the errors error message.
  func (e *Error) Error() string {
      return e.Message
  }
  
  func newError(tp ErrorType, message string) *Error {
      return &amp;Error{
          Type:    tp,
          Message: message,
      }
  }
  </code></pre>
  <p>So they have this custom &quot;Error&quot; type.  And in the Parse() method above, internally, the error is getting created with a block of code like this:</p>
  <pre><code>    help.ShowHelp = func() error {
          var b bytes.Buffer
          p.WriteHelp(&amp;b)
          return newError(ErrHelp, b.String())
      }
  </code></pre>
  <p>As you can see newError() returns &quot;*Error&quot; as it's type.  But the anonymous function just above returns type &quot;error&quot; - so those types must be compatible.(?)</p>
  <p>But now back to the original problem - I'm just trying to see if my &quot;err&quot; is an &quot;Error&quot; and has member &quot;Type&quot; equal to ErrHelp.  So I try this:</p>
  <pre><code>if err != nil &amp;&amp; flags.Error(err).Type == flags.ErrHelp {
  </code></pre>
  <p>Or even just this:</p>
  <pre><code>fmt.Printf(&quot;test:&quot;, flags.Error(err))
  </code></pre>
  <p>And either way the compiler gives me:</p>
  <blockquote>
  <p>main.go:37: cannot convert err (type error) to type flags.Error</p>
  </blockquote>
  <p>But does not state why that conversion can't be done.  Any ideas?</p>
  <p>(I don't get how &quot;*Error&quot; successfully converts to &quot;error&quot; in the anonymous function above, and I even more don't get why if that works then I can't convert it back the other way...  I must be missing something really dumb here, but I'm not seeing what it is.)</p>