Visitar URL original
Don't assert that an eqq is followed by another instruction · jruby/jruby@8710999 · GitHub
Skip to content

Commit 8710999

Browse files
committed
Don't assert that an eqq is followed by another instruction
canOmitStoreLoad asserted that the instruction after an eqq is never null, but it's null whenever the eqq ends its basic block. Inside a block, each in clause of a case/in does that, because the pattern_end label after the eqq starts a new basic block. With assertions on, those blocks failed to compile. The assertion wasn't protecting anything: a null next instruction just means the store and load can't be omitted, which is what the method returns for patterns anyway. Return false instead. Fixes #9829
1 parent 32d3e80 commit 8710999

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

‎core/src/main/java/org/jruby/ir/targets/JVMVisitor.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1698,7 +1698,8 @@ public void DefineModuleInstr(DefineModuleInstr definemoduleinstr) {
16981698

16991699
// 'when' statements emit a 1;1 use:def temporary which we can omit and just leave eqq result on the stack.
17001700
private boolean canOmitStoreLoad(EQQInstr eqq, Instr nextInstr) {
1701-
assert nextInstr != null: "Somehow EQQ is the last instr in the scope...";
1701+
// nextInstr is null when the eqq ends its basic block, as each in clause's eqq does inside a block
1702+
if (nextInstr == null) return false;
17021703

17031704
return !eqq.isPattern() && nextInstr instanceof BTrueInstr && eqq.getResult().equals(((BTrueInstr) nextInstr).getArg1());
17041705
}

‎spec/compiler/general_spec.rb‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,6 +1216,13 @@ def foo(str: "bar", num: 45, **opts)
12161216
end
12171217
end
12181218

1219+
# See https://github.com/jruby/jruby/issues/9829
1220+
it "compiles a case/in with several in clauses inside a block" do
1221+
run('[0, 1, 2].map { |v| case v; in 0 then :zero; in 1 then :one; else :other; end }') do |x|
1222+
expect(x).to eq [:zero, :one, :other]
1223+
end
1224+
end
1225+
12191226
it "enforces visibility" do
12201227
run('obj = Class.new do
12211228
def a; true; end

0 commit comments

Comments
 (0)