title: Why can't I declare a nested class that is a subclass of a sealed class?
body: <p>The <a href="https://kotlinlang.org/docs/reference/sealed-classes.html" rel="nofollow noreferrer">Kotlin documentation</a> states:</p>
  <blockquote>
  <p>A sealed class can have subclasses, but all of them must be declared in the same file as the sealed class itself. (Before Kotlin 1.1, the rules were even more strict: classes had to be nested inside the declaration of the sealed class).</p>
  </blockquote>
  <p>Admittedly, this is worded as a necessary but not sufficient condition, but it does imply (by lack of anything contrary) that I can declare a subclass of a sealed class anywhere in the same file.</p>
  <p>Given that the following code compiles:</p>
  <pre class="lang-kotlin prettyprint-override"><code>//class Jungle {
      sealed class Animal
      class Tiger : Animal()
  //}
  </code></pre>
  <p>why does the following not compile:</p>
  <pre class="lang-kotlin prettyprint-override"><code>class Jungle {
      sealed class Animal
      class Tiger : Animal()
  }
  </code></pre>
  <p>The second snippet gives the following errors with Intellij Kotlin plugin version <code>1.3.72-release-IJ2020.1-5</code>:</p>
  <pre><code>Error:(3, 20) Kotlin: Cannot access '&lt;init&gt;': it is private in 'Animal'
  Error:(3, 20) Kotlin: This type is sealed, so it can be inherited by only its own nested classes or objects
  </code></pre>
  <p>In fact, the second error message here seems to directly contradict the documentation.</p>