Skip to content

Commit

Permalink
Make patchCompletingNormallyCases void returning
Browse files Browse the repository at this point in the history
  • Loading branch information
biboudis committed Sep 1, 2023
1 parent 5b0bf6c commit c46952b
Showing 1 changed file with 5 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ private void handleSwitch(JCTree tree,
boolean previousCompletesNormally = false;
boolean hasDefault = false;

cases = patchCompletingNormallyCases(cases);
patchCompletingNormallyCases(cases);

for (var c : cases) {
List<JCCaseLabel> clearedPatterns = c.labels;
Expand All @@ -543,7 +543,8 @@ private void handleSwitch(JCTree tree,
validCaseLabelList = clearedPatterns.head.hasTag(Tag.PATTERNCASELABEL);
}

if (validCaseLabelList && !previousCompletesNormally || c.guard != null) {
if ((validCaseLabelList && !previousCompletesNormally) ||
c.guard != null) {
List<JCPatternCaseLabel> labels = clearedPatterns.stream().map(cp -> (JCPatternCaseLabel)cp).collect(List.collector());
bindingContext = new BasicBindingContext();
VarSymbol prevCurrentValue = currentValue;
Expand Down Expand Up @@ -661,7 +662,7 @@ private void handleSwitch(JCTree tree,
}

// Duplicates the block statement where needed.
// Processes cases in reverse order, e.g.
// Processes cases in place, e.g.
// switch (obj) {
// case Integer _ when ((Integer) obj) > 0:
// case String _ when !((String) obj).isEmpty():
Expand All @@ -678,8 +679,7 @@ private void handleSwitch(JCTree tree,
// return 1;
// ...
// }
private static List<JCCase> patchCompletingNormallyCases(List<JCCase> cases) {
ListBuffer<JCCase> newCases = new ListBuffer<>();
private static void patchCompletingNormallyCases(List<JCCase> cases) {
for (int j = cases.size() - 1; j >= 0; j--) {
var currentCase = cases.get(j);

Expand All @@ -689,9 +689,7 @@ private static List<JCCase> patchCompletingNormallyCases(List<JCCase> cases) {
var nextCase = cases.get(j + 1);
currentCase.stats = currentCase.stats.appendList(nextCase.stats);
}
newCases.add(currentCase);
}
return newCases.toList().reverse();
}

//where:
Expand Down

0 comments on commit c46952b

Please sign in to comment.