Skip to content

Commit

Permalink
Always assign masgn destructured args in block as block-local.
Browse files Browse the repository at this point in the history
Fixes #2960
  • Loading branch information
headius committed Jan 15, 2016
1 parent d3f90ac commit e179f01
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
6 changes: 6 additions & 0 deletions core/src/main/java/org/jruby/parser/ParserSupport.java
Expand Up @@ -236,6 +236,12 @@ public AssignableNode assignable(Token lhs, Node value) {
"identifier " + (String) lhs.getValue() + " is not valid", lhs.getValue());
}

// We know it has to be tLABEL or tIDENTIFIER so none of the other assignable logic is needed
public AssignableNode assignableInCurr(Token name, Node value) {
currentScope.addVariableThisScope(name.getValue().toString());
return currentScope.assign(lexer.getPosition(), name.getValue().toString(), makeNullNil(value));
}

/**
* Wraps node with NEWLINE node.
*
Expand Down
10 changes: 5 additions & 5 deletions core/src/main/java/org/jruby/parser/Ruby19Parser.java
Expand Up @@ -3092,7 +3092,7 @@ public Object yyparse (RubyYaccLexer yyLex) throws java.io.IOException {
};
states[339] = new ParserState() {
@Override public Object execute(ParserSupport support, RubyYaccLexer lexer, Object yyVal, Object[] yyVals, int yyTop) {
yyVal = support.assignable(((Token)yyVals[0+yyTop]), NilImplicitNode.NIL);
yyVal = support.assignableInCurr(((Token)yyVals[0+yyTop]), NilImplicitNode.NIL);
return yyVal;
}
};
Expand Down Expand Up @@ -3122,13 +3122,13 @@ public Object yyparse (RubyYaccLexer yyLex) throws java.io.IOException {
};
states[344] = new ParserState() {
@Override public Object execute(ParserSupport support, RubyYaccLexer lexer, Object yyVal, Object[] yyVals, int yyTop) {
yyVal = new MultipleAsgn19Node(((ListNode)yyVals[-3+yyTop]).getPosition(), ((ListNode)yyVals[-3+yyTop]), support.assignable(((Token)yyVals[0+yyTop]), null), null);
yyVal = new MultipleAsgn19Node(((ListNode)yyVals[-3+yyTop]).getPosition(), ((ListNode)yyVals[-3+yyTop]), support.assignableInCurr(((Token)yyVals[0+yyTop]), null), null);
return yyVal;
}
};
states[345] = new ParserState() {
@Override public Object execute(ParserSupport support, RubyYaccLexer lexer, Object yyVal, Object[] yyVals, int yyTop) {
yyVal = new MultipleAsgn19Node(((ListNode)yyVals[-5+yyTop]).getPosition(), ((ListNode)yyVals[-5+yyTop]), support.assignable(((Token)yyVals[-2+yyTop]), null), ((ListNode)yyVals[0+yyTop]));
yyVal = new MultipleAsgn19Node(((ListNode)yyVals[-5+yyTop]).getPosition(), ((ListNode)yyVals[-5+yyTop]), support.assignableInCurr(((Token)yyVals[-2+yyTop]), null), ((ListNode)yyVals[0+yyTop]));
return yyVal;
}
};
Expand All @@ -3146,13 +3146,13 @@ public Object yyparse (RubyYaccLexer yyLex) throws java.io.IOException {
};
states[348] = new ParserState() {
@Override public Object execute(ParserSupport support, RubyYaccLexer lexer, Object yyVal, Object[] yyVals, int yyTop) {
yyVal = new MultipleAsgn19Node(((Token)yyVals[-1+yyTop]).getPosition(), null, support.assignable(((Token)yyVals[0+yyTop]), null), null);
yyVal = new MultipleAsgn19Node(((Token)yyVals[-1+yyTop]).getPosition(), null, support.assignableInCurr(((Token)yyVals[0+yyTop]), null), null);
return yyVal;
}
};
states[349] = new ParserState() {
@Override public Object execute(ParserSupport support, RubyYaccLexer lexer, Object yyVal, Object[] yyVals, int yyTop) {
yyVal = new MultipleAsgn19Node(((Token)yyVals[-3+yyTop]).getPosition(), null, support.assignable(((Token)yyVals[-2+yyTop]), null), ((ListNode)yyVals[0+yyTop]));
yyVal = new MultipleAsgn19Node(((Token)yyVals[-3+yyTop]).getPosition(), null, support.assignableInCurr(((Token)yyVals[-2+yyTop]), null), ((ListNode)yyVals[0+yyTop]));
return yyVal;
}
};
Expand Down
10 changes: 5 additions & 5 deletions core/src/main/java/org/jruby/parser/Ruby19Parser.y
Expand Up @@ -1240,7 +1240,7 @@ for_var : lhs
}

f_marg : f_norm_arg {
$$ = support.assignable($1, NilImplicitNode.NIL);
$$ = support.assignableInCurr($1, NilImplicitNode.NIL);
}
| tLPAREN f_margs rparen {
$$ = $2;
Expand All @@ -1258,10 +1258,10 @@ f_margs : f_marg_list {
$$ = new MultipleAsgn19Node($1.getPosition(), $1, null, null);
}
| f_marg_list ',' tSTAR f_norm_arg {
$$ = new MultipleAsgn19Node($1.getPosition(), $1, support.assignable($4, null), null);
$$ = new MultipleAsgn19Node($1.getPosition(), $1, support.assignableInCurr($4, null), null);
}
| f_marg_list ',' tSTAR f_norm_arg ',' f_marg_list {
$$ = new MultipleAsgn19Node($1.getPosition(), $1, support.assignable($4, null), $6);
$$ = new MultipleAsgn19Node($1.getPosition(), $1, support.assignableInCurr($4, null), $6);
}
| f_marg_list ',' tSTAR {
$$ = new MultipleAsgn19Node($1.getPosition(), $1, new StarNode(lexer.getPosition()), null);
Expand All @@ -1270,10 +1270,10 @@ f_margs : f_marg_list {
$$ = new MultipleAsgn19Node($1.getPosition(), $1, new StarNode(lexer.getPosition()), $5);
}
| tSTAR f_norm_arg {
$$ = new MultipleAsgn19Node($1.getPosition(), null, support.assignable($2, null), null);
$$ = new MultipleAsgn19Node($1.getPosition(), null, support.assignableInCurr($2, null), null);
}
| tSTAR f_norm_arg ',' f_marg_list {
$$ = new MultipleAsgn19Node($1.getPosition(), null, support.assignable($2, null), $4);
$$ = new MultipleAsgn19Node($1.getPosition(), null, support.assignableInCurr($2, null), $4);
}
| tSTAR {
$$ = new MultipleAsgn19Node($1.getPosition(), null, new StarNode(lexer.getPosition()), null);
Expand Down

0 comments on commit e179f01

Please sign in to comment.