Skip to content

Commit

Permalink
Showing 3 changed files with 23 additions and 9 deletions.
1 change: 0 additions & 1 deletion spec/truffle/tags/language/block_tags.txt
Original file line number Diff line number Diff line change
@@ -2,4 +2,3 @@ fails:A block yielded a single Array assigns elements to required arguments when
fails:A block yielded a single Array assigns the last element to a non-keyword argument if #to_hash returns nil
fails:A block yielded a single Array calls #to_hash on the argument but does not use the result when no keywords are present
fails:A block yielded a single Array calls #to_hash on the last element when there are more arguments than parameters
fails:A block yielded a single Object receives the object if #to_ary returns nil
Original file line number Diff line number Diff line change
@@ -99,6 +99,10 @@ public Object cast(Object nil) {
public Object cast(VirtualFrame frame, DynamicObject object) {
final Object result = toArrayNode.call(frame, object, "to_ary", null);

if (result == nil()) {
return nil();
}

if (result == DispatchNode.MISSING) {
return nil();
}
Original file line number Diff line number Diff line change
@@ -21,17 +21,16 @@
import org.jruby.ast.types.INameNode;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.RubyRootNode;
import org.jruby.truffle.nodes.arguments.CheckArityNode;
import org.jruby.truffle.nodes.arguments.MissingArgumentBehaviour;
import org.jruby.truffle.nodes.arguments.ReadBlockNode;
import org.jruby.truffle.nodes.arguments.ReadPreArgumentNode;
import org.jruby.truffle.nodes.arguments.ShouldDestructureNode;
import org.jruby.truffle.nodes.arguments.*;
import org.jruby.truffle.nodes.cast.ArrayCastNodeGen;
import org.jruby.truffle.nodes.control.*;
import org.jruby.truffle.nodes.control.AndNode;
import org.jruby.truffle.nodes.control.IfNode;
import org.jruby.truffle.nodes.control.SequenceNode;
import org.jruby.truffle.nodes.core.ProcNodes.Type;
import org.jruby.truffle.nodes.dispatch.RespondToNode;
import org.jruby.truffle.nodes.locals.FlipFlopStateNode;
import org.jruby.truffle.nodes.locals.ReadFrameSlotNodeGen;
import org.jruby.truffle.nodes.locals.ReadLocalVariableNode;
import org.jruby.truffle.nodes.locals.WriteLocalVariableNode;
import org.jruby.truffle.nodes.methods.*;
import org.jruby.truffle.nodes.supercall.ReadSuperArgumentsNode;
@@ -98,16 +97,28 @@ public BlockDefinitionNode compileBlockNode(SourceSection sourceSection, String
if (shouldConsiderDestructuringArrayArg(arity)) {
final RubyNode readArrayNode = new ReadPreArgumentNode(context, sourceSection, 0, MissingArgumentBehaviour.RUNTIME_ERROR);
final RubyNode castArrayNode = ArrayCastNodeGen.create(context, sourceSection, readArrayNode);

final FrameSlot arraySlot = environment.declareVar(environment.allocateLocalTemp("destructure"));
final RubyNode writeArrayNode = new WriteLocalVariableNode(context, sourceSection, castArrayNode, arraySlot);

final LoadArgumentsTranslator destructureArgumentsTranslator = new LoadArgumentsTranslator(currentNode, context, source, isProc, this);
destructureArgumentsTranslator.pushArraySlot(arraySlot);
final RubyNode newDestructureArguments = argsNode.accept(destructureArgumentsTranslator);

final RubyNode shouldDestructure = new ShouldDestructureNode(context, sourceSection, new RespondToNode(context, sourceSection, readArrayNode, "to_ary"));

final RubyNode arrayWasNotNil = SequenceNode.sequence(context, sourceSection,
writeArrayNode,
new NotNode(context, sourceSection, new IsNilNode(context, sourceSection, new ReadLocalVariableNode(context, sourceSection, arraySlot))));

final RubyNode shouldDestructureAndArrayWasNotNil = new AndNode(context, sourceSection,
shouldDestructure,
arrayWasNotNil);

preludeProc = new IfNode(context, sourceSection,
new ShouldDestructureNode(context, sourceSection, new RespondToNode(context, sourceSection, readArrayNode, "to_ary")),
SequenceNode.sequence(context, sourceSection, writeArrayNode, newDestructureArguments), loadArguments);
shouldDestructureAndArrayWasNotNil,
newDestructureArguments,
loadArguments);
} else {
preludeProc = loadArguments;
}

0 comments on commit 66a2c32

Please sign in to comment.