From 1fa469861158c777d7650ff1d75cafc22ed221b2 Mon Sep 17 00:00:00 2001 From: Svetlana Isakova Date: Wed, 18 Apr 2012 20:42:55 +0400 Subject: [PATCH] KT-1778 Automatically cast error #KT-1778 fixed --- .../jet/lang/types/expressions/DataFlowUtils.java | 4 ++-- .../tests/nullabilityAndAutoCasts/kt1778.jet | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 compiler/testData/diagnostics/tests/nullabilityAndAutoCasts/kt1778.jet diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/DataFlowUtils.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/DataFlowUtils.java index 1697a8dcced..d2f9a040861 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/DataFlowUtils.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/DataFlowUtils.java @@ -48,7 +48,7 @@ public class DataFlowUtils { @NotNull public static DataFlowInfo extractDataFlowInfoFromCondition(@Nullable JetExpression condition, final boolean conditionValue, @Nullable final WritableScope scopeToExtend, final ExpressionTypingContext context) { if (condition == null) return context.dataFlowInfo; - final Ref result = new Ref(context.dataFlowInfo); + final Ref result = new Ref(null); condition.accept(new JetVisitorVoid() { @Override public void visitIsExpression(JetIsExpression expression) { @@ -148,7 +148,7 @@ public class DataFlowUtils { if (result.get() == null) { return context.dataFlowInfo; } - return result.get(); + return context.dataFlowInfo.and(result.get()); } @Nullable diff --git a/compiler/testData/diagnostics/tests/nullabilityAndAutoCasts/kt1778.jet b/compiler/testData/diagnostics/tests/nullabilityAndAutoCasts/kt1778.jet new file mode 100644 index 00000000000..b4c46e0b96e --- /dev/null +++ b/compiler/testData/diagnostics/tests/nullabilityAndAutoCasts/kt1778.jet @@ -0,0 +1,11 @@ +//KT-1778 Automatically cast error +package kt1778 + +fun main(args : Array) { + val x = args[0]: Any + if(x is java.lang.CharSequence) { + if ("a" == x) x.length() else x.length() // OK + if ("a" == x || "b" == x) x.length() else x.length() // <– THEN ERROR + if ("a" == x && "a" == x) x.length() else x.length() // <– ELSE ERROR + } +} \ No newline at end of file