Skip to content

Commit

Permalink
#2920 Properly handle flow abruption in ternary condition
Browse files Browse the repository at this point in the history
  • Loading branch information
hurricup committed Oct 19, 2024
1 parent eac1718 commit 78939f7
Show file tree
Hide file tree
Showing 7 changed files with 161 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,9 @@ public void visitTernaryExpr(@NotNull PsiPerlTernaryExpr o) {
}
children[0].accept(this);
Instruction conditionInstruction = prevInstruction;
startConditionalNode(o, children[0], true);
if (conditionInstruction != null) {
startConditionalNode(o, children[0], true);
}
children[1].accept(this);
Instruction trueInstruction = prevInstruction;
prevInstruction = conditionInstruction;
Expand Down
3 changes: 3 additions & 0 deletions plugin/src/test/java/unit/perl/PerlControlFlowTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ protected String getBaseDataPath() {
return "unit/perl/controlFlow";
}

@Test
public void testTernaryDieCondition() { doTest(); }

@Test
public void testCheckOrDie() { doTest(); }

Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
die("some") <error descr="Unreachable code">?</error> "one"<error descr="Unreachable code">:</error> "<error descr="Unreachable code">Two</error>";
die("some") ? "<error descr="Unreachable code">one</error>": "<error descr="Unreachable code">Two</error>";
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
die("some") ? "one": "Two";
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
0(1) element: null (InstructionImpl)
1(2) element: Perl5 (InstructionImpl)
2(3) element: PsiPerlStringDqImpl(Perl5: STRING_DQ) (InstructionImpl)
3(6) element: PsiPerlSubCallImpl(SUB_CALL) (PerlNoResultInstruction)
4(6) element: PsiPerlStringDqImpl(Perl5: STRING_DQ) (InstructionImpl)
5(6) element: PsiPerlStringDqImpl(Perl5: STRING_DQ) (InstructionImpl)
6() element: null (InstructionImpl)
4 changes: 2 additions & 2 deletions plugin/src/testFixtures/java/base/PerlLightTestCaseBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -1873,10 +1873,10 @@ private void saveSvgFile(final @NotNull String outSvgFile, final @NotNull Instru
}
case PartialConditionalInstructionImpl partialConditionalInstruction ->
builder.append("\n").append("Its ").append(partialConditionalInstruction.getResult()).
append(" branch, condition: ").append(partialConditionalInstruction.getConditionText());
append(" branch, condition: ").append(escape(partialConditionalInstruction.getConditionText()));
case ConditionalInstruction conditionalInstruction ->
builder.append("\n").append("Its ").append(conditionalInstruction.getResult()).
append(" branch, condition: ").append(getTextSafe(conditionalInstruction.getCondition()));
append(" branch, condition: ").append(escape(getTextSafe(conditionalInstruction.getCondition())));
default -> {
}
}
Expand Down

0 comments on commit 78939f7

Please sign in to comment.