Accessing to synthetic properties on smart casted Android components crashed compiler

I have some problems after Kotlin 1.1.2-5 for my Android project. The gradle log has following output:

e: org.jetbrains.kotlin.codegen.CompilationException: Back-end (JVM) Internal error: Invalid Android class type: UNKNOWN
Cause: Invalid Android class type: UNKNOWN

(... some code snippets)

The root cause was thrown at: AndroidExpressionCodegenExtension.kt:210
	at org.jetbrains.kotlin.codegen.ExpressionCodegen.genQualified(ExpressionCodegen.java:324)
	at org.jetbrains.kotlin.codegen.ExpressionCodegen.genQualified(ExpressionCodegen.java:287)
	at org.jetbrains.kotlin.codegen.ExpressionCodegen.gen(ExpressionCodegen.java:330)
  	at org.jetbrains.kotlin.codegen.CallGenerator$DefaultCallGenerator.genValueAndPut(CallGenerator.kt:61)
    at org.jetbrains.kotlin.codegen.CallBasedArgumentGenerator.generateExpression(CallBasedArgumentGenerator.java:77)

After some research, I found this is related to smart cast and synthetic properties.

Here’s code that crashes compiler:

val bad = DialogInterface.OnShowListener { di ->
    di as Dialog
    di.any_view_id // Imported synthetic properties
}

di in third line is smart casted to Dialog, however, seems compiler doesn’t aware that.

Here’s an workaround:

val good = DialogInterface.OnShowListener { di ->
    val dialog = di as Dialog
    dialog.any_view_id // Imported synthetic properties
}

I hope Kotlin team could make compiler aware of smart casts to prevent this error.

Could you please file a YouTrack issue for this problem? Thanks!

This is my first time submitting YouTrack issue: https://youtrack.jetbrains.com/issue/KT-18545

Hope there’s no problem in this report!