Skip to content

Commit

Permalink
Dynamic constructs were never using frozen strings for StrNodes.
Browse files Browse the repository at this point in the history
We had a check for this in IRBuilder but at some point we ended up
adding a copyAndReturn to buildStr.  This defeated the check.
enebo committed Jun 8, 2016
1 parent d8c74bf commit f30009c
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions core/src/main/java/org/jruby/ir/IRBuilder.java
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@
import org.jruby.ast.*;
import org.jruby.ast.types.INameNode;
import org.jruby.compiler.NotCompilableException;
import org.jruby.lexer.yacc.ISourcePosition;
import org.jruby.runtime.ArgumentDescriptor;
import org.jruby.runtime.ArgumentType;
import org.jruby.ir.instructions.*;
@@ -2182,7 +2183,7 @@ public Operand buildDot(final DotNode dotNode) {
}

private Operand dynamicPiece(Node pieceNode) {
Operand piece = build(pieceNode);
Operand piece = pieceNode instanceof StrNode ? buildStrRaw((StrNode) pieceNode) : build(pieceNode);

if (piece instanceof StringLiteral) {
piece = ((StringLiteral)piece).frozenString;
@@ -3445,15 +3446,19 @@ public Operand buildSplat(SplatNode splatNode) {
}

public Operand buildStr(StrNode strNode) {
Operand literal = buildStrRaw(strNode);

return literal instanceof FrozenString ? literal : copyAndReturnValue(literal);
}

public Operand buildStrRaw(StrNode strNode) {
if (strNode instanceof FileNode) return new Filename();

Operand literal = strNode.isFrozen() ?
new FrozenString(strNode.getValue(), strNode.getCodeRange(), strNode.getPosition().getFile(), strNode.getPosition().getLine()) :
new StringLiteral(strNode.getValue(), strNode.getCodeRange(), strNode.getPosition().getFile(), strNode.getPosition().getLine());
ISourcePosition pos = strNode.getPosition();

Operand result = copyAndReturnValue(literal);
if (strNode.isFrozen()) return new FrozenString(strNode.getValue(), strNode.getCodeRange(), pos.getFile(), pos.getLine());

return result;
return new StringLiteral(strNode.getValue(), strNode.getCodeRange(), pos.getFile(), pos.getLine());
}

private Operand buildSuperInstr(Operand block, Operand[] args) {

0 comments on commit f30009c

Please sign in to comment.