title: Kotlin compiler not warning about potential null pointer exception
body: <p>I have this simple kotlin snipped that tries to map list elements to strings like this:</p>
  <pre class="lang-kotlin prettyprint-override"><code>sealed class MySealedClass
  
  class MyClass1 : MySealedClass()
  
  class MyClass2 : MySealedClass()
  
  fun doTheMapThing(elements: List&lt;MySealedClass&gt;): List&lt;String&gt; {
      return elements.flatMap {
          when (it) {
              is MyClass1 -&gt; listOf(&quot;Yeah&quot;)
              is MyClass2 -&gt; null
          }
      }
  }
  </code></pre>
  <p>In the <code>flatMap</code>, the <code>when</code> either maps to a list or to <code>null</code>, so the effective return type of the <code>when</code> is <code>List&lt;String&gt;?</code>. I was a bit surprised to see this compiling without any issues. Shouldn't the kotlin compiler warn about this? When I extract the <code>when</code> to a function, I get a proper compiler error. Am I missing something here or could this be a bug?</p>
  <p>Using kotlin 1.5.31</p>