title: Why is casting the type still necessary even though it has already been assured in this example?
body: <p>Today I came across this section in the <a href="https://kotlinlang.org/docs/reference/typecasts.html#smart-casts" rel="nofollow noreferrer">Kotlin Docs</a>. Called "smart casts", Kotlin seems to "insert (safe) casts automatically when needed":</p>
  
  <blockquote>
    <p>In many cases, one does not need to use explicit cast operators in
    Kotlin, because the compiler tracks the is-checks for immutable values
    and inserts (safe) casts automatically when needed:</p>
  
  <pre><code>fun demo(x: Any) {
      if (x is String) {
          print(x.length) // x is automatically cast to String
      }
  }
  </code></pre>
  </blockquote>
  
  <p>I don't understand what "smart casting" does in this example. There seems to be nothing that requires casting, as <code>x</code> will always be String and thus <code>x.length</code> will always work, no casting required. What is happening on the <code>print</code> line exactly? Thanks in advance!</p>