JS: when none of exhaustive when clauses match, generate code that throws exception. See KT-12194

This commit is contained in:
Alexey Andreev
2016-12-27 17:18:47 +03:00
parent 3384c6f603
commit 7f0166623d
7 changed files with 137 additions and 12 deletions
@@ -24,6 +24,7 @@ import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.DescriptorUtils
import org.jetbrains.kotlin.resolve.bindingContextUtil.isUsedAsExpression
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
import org.jetbrains.kotlin.types.KotlinType
@@ -141,4 +142,16 @@ object CodegenUtil {
function.returnType != null &&
isReturnTypeOk(function.returnType!!)
}
@JvmStatic
fun BindingContext.isExhaustive(whenExpression: KtWhenExpression, isStatement: Boolean): Boolean {
val slice = if (isStatement && !whenExpression.isUsedAsExpression(this)) {
BindingContext.IMPLICIT_EXHAUSTIVE_WHEN
}
else {
BindingContext.EXHAUSTIVE_WHEN
}
return this[slice, whenExpression] == true
}
}