diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowProcessor.java b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowProcessor.java index 4fa0b558482..b47ed777e11 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowProcessor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowProcessor.java @@ -1203,7 +1203,9 @@ public class JetControlFlowProcessor { JetExpression left = expression.getLeft(); if (operationType == JetTokens.COLON || operationType == JetTokens.AS_KEYWORD || operationType == JetTokens.AS_SAFE) { generateInstructions(left); - copyValue(left, expression); + if (builder.getBoundValue(left) != null) { + createNonSyntheticValue(expression, MagicKind.CAST, left); + } } else { visitJetElement(expression); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/instructions/eval/operationInstructions.kt b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/instructions/eval/operationInstructions.kt index fd62a4e6cf1..97e8685ace0 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/instructions/eval/operationInstructions.kt +++ b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/instructions/eval/operationInstructions.kt @@ -139,6 +139,7 @@ public enum class MagicKind { NOT_NULL_ASSERTION EQUALS_IN_WHEN_CONDITION IS + CAST CALLABLE_REFERENCE // implicit operations LOOP_RANGE_ITERATION diff --git a/compiler/testData/cfg/expressions/casts.instructions b/compiler/testData/cfg/expressions/casts.instructions new file mode 100644 index 00000000000..37eb376d56e --- /dev/null +++ b/compiler/testData/cfg/expressions/casts.instructions @@ -0,0 +1,29 @@ +== foo == +fun foo(a: Any) { + a : String + a as String + a as? String +} +--------------------- +L0: + 1 + v(a: Any) + magic[FAKE_INITIALIZER](a: Any) -> + w(a|) + 2 mark({ a : String a as String a as? String }) + mark(a : String) + r(a) -> + magic[CAST](a : String|) -> + mark(a as String) + r(a) -> + magic[CAST](a as String|) -> + mark(a as? String) + r(a) -> + magic[CAST](a as? String|) -> +L1: + 1 NEXT:[] +error: + PREV:[] +sink: + PREV:[, ] +===================== \ No newline at end of file diff --git a/compiler/testData/cfg/expressions/casts.kt b/compiler/testData/cfg/expressions/casts.kt new file mode 100644 index 00000000000..bca0f907b05 --- /dev/null +++ b/compiler/testData/cfg/expressions/casts.kt @@ -0,0 +1,5 @@ +fun foo(a: Any) { + a : String + a as String + a as? String +} \ No newline at end of file diff --git a/compiler/testData/cfg/expressions/casts.values b/compiler/testData/cfg/expressions/casts.values new file mode 100644 index 00000000000..ea9f97f7838 --- /dev/null +++ b/compiler/testData/cfg/expressions/casts.values @@ -0,0 +1,16 @@ +== foo == +fun foo(a: Any) { + a : String + a as String + a as? String +} +--------------------- + : {<: Any} NEW: magic[FAKE_INITIALIZER](a: Any) -> +a : * NEW: r(a) -> +a : String : * NEW: magic[CAST](a : String|) -> +a : * NEW: r(a) -> +a as String : * NEW: magic[CAST](a as String|) -> +a : * NEW: r(a) -> +a as? String : * NEW: magic[CAST](a as? String|) -> +{ a : String a as String a as? String } : * COPY +===================== \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/jet/cfg/ControlFlowTestGenerated.java b/compiler/tests/org/jetbrains/jet/cfg/ControlFlowTestGenerated.java index 61d7e5c8002..5202f45ea51 100644 --- a/compiler/tests/org/jetbrains/jet/cfg/ControlFlowTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/cfg/ControlFlowTestGenerated.java @@ -374,6 +374,11 @@ public class ControlFlowTestGenerated extends AbstractControlFlowTest { doTest("compiler/testData/cfg/expressions/callableReferences.kt"); } + @TestMetadata("casts.kt") + public void testCasts() throws Exception { + doTest("compiler/testData/cfg/expressions/casts.kt"); + } + @TestMetadata("chainedQualifiedExpression.kt") public void testChainedQualifiedExpression() throws Exception { doTest("compiler/testData/cfg/expressions/chainedQualifiedExpression.kt"); diff --git a/compiler/tests/org/jetbrains/jet/cfg/PseudoValueTestGenerated.java b/compiler/tests/org/jetbrains/jet/cfg/PseudoValueTestGenerated.java index 4e55d0e22fc..1f9f1c327fe 100644 --- a/compiler/tests/org/jetbrains/jet/cfg/PseudoValueTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/cfg/PseudoValueTestGenerated.java @@ -378,6 +378,11 @@ public class PseudoValueTestGenerated extends AbstractPseudoValueTest { doTest("compiler/testData/cfg/expressions/callableReferences.kt"); } + @TestMetadata("casts.kt") + public void testCasts() throws Exception { + doTest("compiler/testData/cfg/expressions/casts.kt"); + } + @TestMetadata("chainedQualifiedExpression.kt") public void testChainedQualifiedExpression() throws Exception { doTest("compiler/testData/cfg/expressions/chainedQualifiedExpression.kt");