Smartcast is impossible because property has open or custom getter
<p>I am learning Kotlin. My code is as follows:</p>

<pre><code>override fun onViewCreated(view: View?, savedInstanceState: Bundle?) {
    super.onViewCreated(view, savedInstanceState)
    decoupler.attachNotifier(this)
    if(activity is ScreenRouter) {
        decoupler.attachRouter(activity)
    }
}
</code></pre>

<p><code>attachRouter()</code> method: </p>

<pre><code> fun attachRouter(router: ScreenRouter?) {
    this.router = router
}
</code></pre>

<p>As written in <a href="https://kotlinlang.org/docs/reference/typecasts.html" rel="noreferrer">documentation</a>, kotlin automatically casts to type after checking with is operator. So, I expected that it would work. But instead it bothers me with compilation error saying : </p>

<p><strong>Smartcast to <code>ScreenRouter</code> is impossible because <code>activity</code> is a property that has open or custom getter.</strong></p>

<p>I thought maybe error is because activity can be nullable so I tried:</p>

<pre><code>if(activity!=null &amp;&amp; activity is ScreenRouter) {
     decoupler.attachRouter(activity)
}
</code></pre>

<p>But it didn't work and compilation failed with same error.</p>

<p>However, following code works fine:</p>

<pre><code>if(activity is ScreenRouter) {
    decoupler.attachRouter(activity as ScreenRouter)
}
</code></pre>

<p>Its okay but above error doesn't seem to explain anything about why smartcast fails. I am not a Kotlin expert, I'm just a beginner learning Kotlin. I found no documentation anywhere. These kind of error descriptions makes Kotlin horrible to learn. Can anyone explain in simple terms?</p>