Skip to content

Commit

Permalink
single pattern not properly working and we had a printf for error str…
Browse files Browse the repository at this point in the history
…ing getting created in non-single pattern matches
  • Loading branch information
enebo committed Nov 29, 2023
1 parent 725c5cb commit 1710cd2
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions core/src/main/java/org/jruby/ir/IRBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -1461,8 +1461,10 @@ private void buildArrayPattern(Label testEnd, Variable result, Variable deconstr
label("min_args_check_end", minArgsCheck -> {
BIntInstr.Op compareOp = pattern.hasRestArg() ? BIntInstr.Op.GTE : BIntInstr.Op.EQ;
addInstr(new BIntInstr(minArgsCheck, compareOp, length, minArgsCount));
fcall(errorString, buildSelf(), "sprintf",
new FrozenString("%s: %s length mismatch (given %d, expected %d)"), deconstructed, deconstructed, as_fixnum(length), as_fixnum(minArgsCount));
if (isSinglePattern) {
fcall(errorString, buildSelf(), "sprintf",
new FrozenString("%s: %s length mismatch (given %d, expected %d)"), deconstructed, deconstructed, as_fixnum(length), as_fixnum(minArgsCount));
}
addInstr(new CopyInstr(result, fals()));
jump(testEnd);
});
Expand Down Expand Up @@ -1788,14 +1790,15 @@ public Operand buildPatternCase(PatternCaseNode patternCase) {

// build each "when"
Variable deconstructed = copy(buildNil());
for (Node aCase : patternCase.getCases().children()) {
Node[] cases = patternCase.getCases().children();
boolean isSinglePattern = cases.length == 1;
for (Node aCase : cases) {
InNode inNode = (InNode) aCase;
Label bodyLabel = getNewLabel();

boolean isSinglePattern = inNode.isSinglePattern();

Variable eqqResult = copy(tru());
labels.add(bodyLabel);

buildPatternMatch(eqqResult, deconstructed, inNode.getExpression(), value, false, isSinglePattern, errorString);
addInstr(createBranch(eqqResult, tru(), bodyLabel));
bodies.put(bodyLabel, inNode.getBody());
Expand Down

0 comments on commit 1710cd2

Please sign in to comment.