Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[IR] Fixed bug generating IR passing splats in certain situations

needed a special case for ArrayNode (SplatNode (...)) AST structure.
Need to figure out if/how this special case can be avoided.
  • Loading branch information...
commit fa4a87176b5bb1bc27f869b30db55339719a6c6b 1 parent a9a50e0
@subbuss subbuss authored
View
37 src/org/jruby/compiler/ir/IRBuilder.java
@@ -683,17 +683,40 @@ protected void buildCallArgNode(List<Operand> argsList, Node args, IRScope s) {
argsList.add(build(n.getSecondNode(), s));
break;
}
- case SPLATNODE: {
- argsList.add(build((SplatNode)args, s));
- break;
- }
case ARRAYNODE: {
ArrayNode arrayNode = (ArrayNode)args;
if (arrayNode.isLightweight()) {
- // explode array, it's an internal "args" array
- for (Node n : arrayNode.childNodes()) {
- argsList.add(build(n, s));
+ List<Node> children = arrayNode.childNodes();
+ if (children.size() == 1) {
+ // skipOverNewlines is required because the parser inserts a NewLineNode in between!
+ Node child = skipOverNewlines(s, children.get(0));
+ Operand childOperand = build(child, s);
+ if (child instanceof SplatNode) {
+ // SSS: If the only child is a splat, the splat is supposed to get through
+ // as an array without being expanded into the call arg list.
+ //
+ // In 1.9 mode, foo=*1 is supposed to store [1], but foo(*1) is supposed to store 1.
+ // The AST for the former is: ArrayNode(Splat19Node(..))
+ // The AST for the latter is: Splat19Node(..)
+ //
+ // In 1.8 mode, foo=[*1] is supposed to store [1]
+ // The AST for this is: ArrayNode(SplatNode(..))
+ //
+ // Why the special case?
+ //
+ // Since splats in call args are always expanded, we convert the splat
+ // into a compound array: *n --> args-cat([], *n)
+ Splat splat = (Splat)childOperand;
+ childOperand = new CompoundArray(new Array(), splat.getArray());
+ }
+ argsList.add(childOperand);
+ } else {
+ // explode array, it's an internal "args" array
+ for (Node n: children) {
+ argsList.add(build(n, s));
+ }
}
+ break;
} else {
// use array as-is, it's a literal array
argsList.add(build(arrayNode, s));
View
1  src/org/jruby/compiler/ir/operands/Array.java
@@ -17,6 +17,7 @@
public class Array extends Operand {
final public Operand[] elts;
+ // SSS FIXME: Do we create a special-case for zero-length arrays?
public Array() {
elts = new Operand[0];
}
Please sign in to comment.
Something went wrong with that request. Please try again.