From d9358d44e77ff2117560f20c859e0f6a58993c4c Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Wed, 17 Aug 2016 16:46:03 +0300 Subject: [PATCH] KT-13426 related : added assertion to prevent smart cast type rewriting for (expression, call) or (expression, implicit receiver) pair --- .../resolve/calls/smartcasts/SmartCastManager.kt | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/smartcasts/SmartCastManager.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/smartcasts/SmartCastManager.kt index 950fd1de151..51b621b2626 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/smartcasts/SmartCastManager.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/smartcasts/SmartCastManager.kt @@ -122,6 +122,12 @@ class SmartCastManager { if (dataFlowValue.isStable) { val oldSmartCasts = trace[SMARTCAST, expression] val newSmartCast = SingleSmartCast(call, type) + if (oldSmartCasts != null) { + val oldType = oldSmartCasts.type(call) + if (oldType != null && oldType != type) { + throw AssertionError("Rewriting key $call for smart cast on ${expression.text}") + } + } trace.record(SMARTCAST, expression, oldSmartCasts?.let { it + newSmartCast } ?: newSmartCast) if (recordExpressionType) { //TODO @@ -165,6 +171,13 @@ class SmartCastManager { if (receiver is ImplicitReceiver) { val oldSmartCasts = c.trace[IMPLICIT_RECEIVER_SMARTCAST, calleeExpression] val newSmartCasts = ImplicitSmartCasts(receiver, possibleType) + if (oldSmartCasts != null) { + val oldType = oldSmartCasts.receiverTypes[receiver] + if (oldType != null && oldType != possibleType) { + throw AssertionError("Rewriting key $receiver for implicit smart cast on ${calleeExpression.text}: " + + "was $oldType, now $possibleType") + } + } c.trace.record(IMPLICIT_RECEIVER_SMARTCAST, calleeExpression, oldSmartCasts?.let { it + newSmartCasts } ?: newSmartCasts)