From f11621615ba3959c68d47f262a46982d732c4820 Mon Sep 17 00:00:00 2001 From: Alexey Sedunov Date: Mon, 1 Sep 2014 13:41:44 +0400 Subject: [PATCH] Pseudocode: Do not generate VALUE_CONSUMER if property delegate has no value (EA-59276) --- .../jet/lang/cfg/JetControlFlowProcessor.java | 11 +++++++---- .../unreachableDelegation.instructions | 17 +++++++++++++++++ .../properties/unreachableDelegation.kt | 1 + .../properties/unreachableDelegation.values | 5 +++++ .../jet/cfg/ControlFlowTestGenerated.java | 5 +++++ .../jet/cfg/PseudoValueTestGenerated.java | 5 +++++ 6 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 compiler/testData/cfg/declarations/properties/unreachableDelegation.instructions create mode 100644 compiler/testData/cfg/declarations/properties/unreachableDelegation.kt create mode 100644 compiler/testData/cfg/declarations/properties/unreachableDelegation.values 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 e34bfa46cd9..4232348d684 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowProcessor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowProcessor.java @@ -1169,7 +1169,9 @@ public class JetControlFlowProcessor { DeclarationDescriptor descriptor = trace.get(BindingContext.DECLARATION_TO_DESCRIPTOR, property); if (!(descriptor instanceof PropertyDescriptor)) return; - List values = Collections.singletonList(builder.getBoundValue(delegate)); + PseudoValue delegateValue = builder.getBoundValue(delegate); + if (delegateValue == null) return; + List typePredicates = KotlinPackage.map( ((PropertyDescriptor) descriptor).getAccessors(), new Function1() { @@ -1179,9 +1181,10 @@ public class JetControlFlowProcessor { } } ); - Map valuesToTypePredicates = - PseudocodePackage.expectedTypeFor(PseudocodePackage.and(typePredicates), values); - builder.magic(property, null, values, valuesToTypePredicates, MagicKind.VALUE_CONSUMER); + Map valuesToTypePredicates = SmartFMap + .emptyMap() + .plus(delegateValue, PseudocodePackage.and(typePredicates)); + builder.magic(property, null, Collections.singletonList(delegateValue), valuesToTypePredicates, MagicKind.VALUE_CONSUMER); } private TypePredicate getTypePredicateByReceiverValue(@Nullable ResolvedCall resolvedCall) { diff --git a/compiler/testData/cfg/declarations/properties/unreachableDelegation.instructions b/compiler/testData/cfg/declarations/properties/unreachableDelegation.instructions new file mode 100644 index 00000000000..3072861821f --- /dev/null +++ b/compiler/testData/cfg/declarations/properties/unreachableDelegation.instructions @@ -0,0 +1,17 @@ +== foo == +val foo: Int by throw NullPointerException() +--------------------- +L0: + 1 + v(val foo: Int by throw NullPointerException()) + mark(throw NullPointerException()) + mark(NullPointerException()) + call(NullPointerException(), ) -> + throw (throw NullPointerException()|) NEXT:[] +L1: + NEXT:[] PREV:[] +error: + PREV:[throw (throw NullPointerException()|)] +sink: + PREV:[, ] +===================== \ No newline at end of file diff --git a/compiler/testData/cfg/declarations/properties/unreachableDelegation.kt b/compiler/testData/cfg/declarations/properties/unreachableDelegation.kt new file mode 100644 index 00000000000..366a8ea418a --- /dev/null +++ b/compiler/testData/cfg/declarations/properties/unreachableDelegation.kt @@ -0,0 +1 @@ +val foo: Int by throw NullPointerException() \ No newline at end of file diff --git a/compiler/testData/cfg/declarations/properties/unreachableDelegation.values b/compiler/testData/cfg/declarations/properties/unreachableDelegation.values new file mode 100644 index 00000000000..95e81c70145 --- /dev/null +++ b/compiler/testData/cfg/declarations/properties/unreachableDelegation.values @@ -0,0 +1,5 @@ +== foo == +val foo: Int by throw NullPointerException() +--------------------- +NullPointerException() : {<: Throwable} NEW: call(NullPointerException(), ) -> +===================== \ 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 afe89de7276..5b1ffcc5cab 100644 --- a/compiler/tests/org/jetbrains/jet/cfg/ControlFlowTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/cfg/ControlFlowTestGenerated.java @@ -335,6 +335,11 @@ public class ControlFlowTestGenerated extends AbstractControlFlowTest { doTest("compiler/testData/cfg/declarations/properties/DelegatedProperty.kt"); } + @TestMetadata("unreachableDelegation.kt") + public void testUnreachableDelegation() throws Exception { + doTest("compiler/testData/cfg/declarations/properties/unreachableDelegation.kt"); + } + } public static Test innerSuite() { diff --git a/compiler/tests/org/jetbrains/jet/cfg/PseudoValueTestGenerated.java b/compiler/tests/org/jetbrains/jet/cfg/PseudoValueTestGenerated.java index 1cbecd0ffd4..20f90518594 100644 --- a/compiler/tests/org/jetbrains/jet/cfg/PseudoValueTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/cfg/PseudoValueTestGenerated.java @@ -337,6 +337,11 @@ public class PseudoValueTestGenerated extends AbstractPseudoValueTest { doTest("compiler/testData/cfg/declarations/properties/DelegatedProperty.kt"); } + @TestMetadata("unreachableDelegation.kt") + public void testUnreachableDelegation() throws Exception { + doTest("compiler/testData/cfg/declarations/properties/unreachableDelegation.kt"); + } + } public static Test innerSuite() {