Skip to content

Commit

Permalink
Showing 2 changed files with 20 additions and 3 deletions.
1 change: 0 additions & 1 deletion spec/truffle/tags/language/block_tags.txt
Original file line number Diff line number Diff line change
@@ -3,4 +3,3 @@ fails:A block yielded a single Array assigns the last element to a non-keyword a
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
fails:Post-args with optional args with a circular argument reference shadows an existing method with the same name as the argument
Original file line number Diff line number Diff line change
@@ -332,6 +332,8 @@ public RubyNode visitDAsgnNode(org.jruby.ast.DAsgnNode node) {
private RubyNode translateLocalAssignment(ISourcePosition sourcePosition, String name, org.jruby.ast.Node valueNode) {
final SourceSection sourceSection = translate(sourcePosition);

final FrameSlot slot = methodBodyTranslator.getEnvironment().getFrameDescriptor().findOrAddFrameSlot(name);

final RubyNode readNode;

if (indexFromEnd == 1) {
@@ -344,8 +346,25 @@ private RubyNode translateLocalAssignment(ISourcePosition sourcePosition, String
readNode = readArgument(sourceSection);
}
} else {

// Optional argument
final RubyNode defaultValue = valueNode.accept(this);
final RubyNode defaultValue;

// The JRuby parser gets local variables that shadow methods with vcalls wrong - fix up here

if (valueNode instanceof org.jruby.ast.VCallNode) {
final String calledName = ((org.jruby.ast.VCallNode) valueNode).getName();

// Just consider the circular case for now as that's all that's speced

if (calledName.equals(name)) {
defaultValue = new ReadLocalVariableNode(context, sourceSection, slot);
} else {
defaultValue = valueNode.accept(this);
}
} else {
defaultValue = valueNode.accept(this);
}

if (argsNode == null) {
throw new IllegalStateException("No arguments node visited");
@@ -371,7 +390,6 @@ private RubyNode translateLocalAssignment(ISourcePosition sourcePosition, String
readNode = ArraySliceNodeGen.create(context, sourceSection, index, indexFromEnd, loadArray(sourceSection));
}

final FrameSlot slot = methodBodyTranslator.getEnvironment().getFrameDescriptor().findOrAddFrameSlot(name);
return new WriteLocalVariableNode(context, sourceSection, readNode, slot);
}

0 comments on commit 038b5a2

Please sign in to comment.