From 85bb4f9b8ed75a6b32e42e005bbfa0c6b145f61a Mon Sep 17 00:00:00 2001 From: Alexey Sedunov Date: Fri, 25 Jul 2014 15:22:58 +0400 Subject: [PATCH] Pseudocode: Generate read instructions on call expression (instead of callee) --- .../jet/lang/cfg/JetControlFlowProcessor.java | 6 +++--- .../invalidVariableCall.instructions | 19 +++++++++++++++++++ .../cfg/expressions/invalidVariableCall.kt | 3 +++ .../expressions/invalidVariableCall.values | 10 ++++++++++ .../jet/cfg/ControlFlowTestGenerated.java | 7 ++++++- .../jet/cfg/PseudoValueTestGenerated.java | 11 +++++++---- 6 files changed, 48 insertions(+), 8 deletions(-) create mode 100644 compiler/testData/cfg/expressions/invalidVariableCall.instructions create mode 100644 compiler/testData/cfg/expressions/invalidVariableCall.kt create mode 100644 compiler/testData/cfg/expressions/invalidVariableCall.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 3e979d10abe..6eae7020b8b 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowProcessor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowProcessor.java @@ -1499,12 +1499,12 @@ public class JetControlFlowProcessor { if (resultingDescriptor instanceof VariableDescriptor) { // If a callee of the call is just a variable (without 'invoke'), 'read variable' is generated. // todo : process arguments for such a case (KT-5387) - JetExpression calleeExpression = PsiUtilPackage.getCalleeExpressionIfAny(callElement); - assert calleeExpression != null + JetExpression callExpression = callElement instanceof JetExpression ? (JetExpression) callElement : null; + assert callExpression != null : "Variable-based call without callee expression: " + callElement.getText(); assert parameterValues.isEmpty() : "Variable-based call with non-empty argument list: " + callElement.getText(); - return builder.readVariable(calleeExpression, resolvedCall, receivers); + return builder.readVariable(callExpression, resolvedCall, receivers); } mark(resolvedCall.getCall().getCallElement()); return builder.call(callElement, resolvedCall, receivers, parameterValues); diff --git a/compiler/testData/cfg/expressions/invalidVariableCall.instructions b/compiler/testData/cfg/expressions/invalidVariableCall.instructions new file mode 100644 index 00000000000..1f7571707c9 --- /dev/null +++ b/compiler/testData/cfg/expressions/invalidVariableCall.instructions @@ -0,0 +1,19 @@ +== foo == +fun foo(i: Int) { + i() +} +--------------------- +L0: + 1 + v(i: Int) + magic[FAKE_INITIALIZER](i: Int) -> + w(i|) + 2 mark({ i() }) + r(i) -> +L1: + 1 NEXT:[] +error: + PREV:[] +sink: + PREV:[, ] +===================== \ No newline at end of file diff --git a/compiler/testData/cfg/expressions/invalidVariableCall.kt b/compiler/testData/cfg/expressions/invalidVariableCall.kt new file mode 100644 index 00000000000..13ed3ad35ad --- /dev/null +++ b/compiler/testData/cfg/expressions/invalidVariableCall.kt @@ -0,0 +1,3 @@ +fun foo(i: Int) { + i() +} \ No newline at end of file diff --git a/compiler/testData/cfg/expressions/invalidVariableCall.values b/compiler/testData/cfg/expressions/invalidVariableCall.values new file mode 100644 index 00000000000..20de0d7f054 --- /dev/null +++ b/compiler/testData/cfg/expressions/invalidVariableCall.values @@ -0,0 +1,10 @@ +== foo == +fun foo(i: Int) { + i() +} +--------------------- + : Int NEW: magic[FAKE_INITIALIZER](i: Int) -> +i : * NEW: r(i) -> +i() !: * +{ i() } !: * 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 82c8864d700..27b688b19e4 100644 --- a/compiler/tests/org/jetbrains/jet/cfg/ControlFlowTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/cfg/ControlFlowTestGenerated.java @@ -368,7 +368,7 @@ public class ControlFlowTestGenerated extends AbstractControlFlowTest { public void testAssignments() throws Exception { doTest("compiler/testData/cfg/expressions/Assignments.kt"); } - + @TestMetadata("callableReferences.kt") public void testCallableReferences() throws Exception { doTest("compiler/testData/cfg/expressions/callableReferences.kt"); @@ -394,6 +394,11 @@ public class ControlFlowTestGenerated extends AbstractControlFlowTest { doTest("compiler/testData/cfg/expressions/incdec.kt"); } + @TestMetadata("invalidVariableCall.kt") + public void testInvalidVariableCall() throws Exception { + doTest("compiler/testData/cfg/expressions/invalidVariableCall.kt"); + } + @TestMetadata("LazyBooleans.kt") public void testLazyBooleans() throws Exception { doTest("compiler/testData/cfg/expressions/LazyBooleans.kt"); diff --git a/compiler/tests/org/jetbrains/jet/cfg/PseudoValueTestGenerated.java b/compiler/tests/org/jetbrains/jet/cfg/PseudoValueTestGenerated.java index 147ffb96e8e..53a00c85775 100644 --- a/compiler/tests/org/jetbrains/jet/cfg/PseudoValueTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/cfg/PseudoValueTestGenerated.java @@ -358,9 +358,7 @@ public class PseudoValueTestGenerated extends AbstractPseudoValueTest { @TestMetadata("compiler/testData/cfg/expressions") public static class Expressions extends AbstractPseudoValueTest { public void testAllFilesPresentInExpressions() throws Exception { - JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", - new File("compiler/testData/cfg/expressions"), Pattern.compile("^(.+)\\.kt$"), - true); + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/cfg/expressions"), Pattern.compile("^(.+)\\.kt$"), true); } @TestMetadata("assignmentToThis.kt") @@ -372,7 +370,7 @@ public class PseudoValueTestGenerated extends AbstractPseudoValueTest { public void testAssignments() throws Exception { doTest("compiler/testData/cfg/expressions/Assignments.kt"); } - + @TestMetadata("callableReferences.kt") public void testCallableReferences() throws Exception { doTest("compiler/testData/cfg/expressions/callableReferences.kt"); @@ -398,6 +396,11 @@ public class PseudoValueTestGenerated extends AbstractPseudoValueTest { doTest("compiler/testData/cfg/expressions/incdec.kt"); } + @TestMetadata("invalidVariableCall.kt") + public void testInvalidVariableCall() throws Exception { + doTest("compiler/testData/cfg/expressions/invalidVariableCall.kt"); + } + @TestMetadata("LazyBooleans.kt") public void testLazyBooleans() throws Exception { doTest("compiler/testData/cfg/expressions/LazyBooleans.kt");