title: Structs cannot be nil, but this is compiling
body: <p>I'm playing with Go Playground and find this code:</p>
  
  <pre><code>package main
  
  import (
      "fmt"
      "time"
  )
  
  type MyError struct {
      When time.Time
      What string
  }
  
  func (e *MyError) Error() string {
      return fmt.Sprintf("at %v, %s",
          e.When, e.What)
  }
  
  func run() error {
      return &amp;MyError{
          time.Now(),
          "it didn't work",
      }
  }
  
  func main() {
      if err := run(); err != nil {
          fmt.Println(err)
      }
  }
  </code></pre>
  
  <p>So here I can see that <code>*MyError</code> implements <code>error</code> interface. However if I remove <code>&amp;</code> in <code>error</code> func and return <code>MyError</code> instead, I receive compile time error: 
  <code>prog.go:19: cannot use MyError literal (type MyError) as type error in return argument: MyError does not implement error (Error method has pointer receiver)</code>. OK I can understand that, so I can make the function <code>Error</code> like this and this will compile and run successfully:</p>
  
  <pre><code>func (e MyError) Error() string {
      return fmt.Sprintf("at %v, %s",
          e.When, e.What)
  }
  
  func run() error {
      return MyError{
          time.Now(),
          "it didn't work",
      }
  }
  </code></pre>
  
  <p>Then I see in <code>main</code> func that there is check if <code>err</code> is <code>nil</code> so if I understand correctly it is perfectly possible func <code>error</code> to return <code>nil</code> in some situations. So it is possible for <code>MyError</code> struct to take <code>nil</code> values. But then if I try to compile this:</p>
  
  <pre><code>import (
      "fmt"
      "time"
  )
  
  type MyError struct {
      When time.Time
      What string
  }
  
  func (e MyError) Error() string {
      return fmt.Sprintf("at %v, %s",
          e.When, e.What)
  }
  
  func run() error {
      return nil
      return MyError{
          time.Now(),
          "it didn't work",
      }
  }
  
  func main() {
      var err2 MyError = nil
  
      fmt.Println(err2)
      if err := run(); err != nil {
          fmt.Println(err)
      }
  }
  </code></pre>
  
  <p>go compiler said that: <code>prog.go:27: cannot use nil as type MyError in assignment
   [process exited with non-zero status]</code></p>
  
  <p>Why in the upper case the compilation is successful and in this case the compilation fails?
  Is it possible for structs to be <code>nil</code> (I guess not, but then why <code>run</code> func compiles?)</p>