Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: c43426679905
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 232ab4366b02
Choose a head ref
  • 4 commits
  • 11 files changed
  • 1 contributor

Commits on Feb 22, 2016

  1. Allow improper names passed to things like kwargs to raise if they

    are not valid formal identifiers.  Fixes MRI test.
    enebo committed Feb 22, 2016
    Copy the full SHA
    7e73719 View commit details
  2. Copy the full SHA
    d8e2d5c View commit details
  3. Copy the full SHA
    99dc2ad View commit details
  4. Now passing tests

    enebo committed Feb 22, 2016
    Copy the full SHA
    232ab43 View commit details
4 changes: 4 additions & 0 deletions core/src/main/java/org/jruby/ext/ripper/HeredocTerm.java
Original file line number Diff line number Diff line change
@@ -70,6 +70,10 @@ public HeredocTerm(ByteList marker, int func, int nth, int line, ByteList lastLi
this.line = line;
this.lastLine = lastLine;
}

public int getFlags() {
return flags;
}

protected int error(RipperLexer lexer, int len, ByteList str, ByteList eos) {
lexer.compile_error("can't find string \"" + eos.toString() + "\" anywhere before EOF");
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/ext/ripper/RipperLexer.java
Original file line number Diff line number Diff line change
@@ -982,7 +982,7 @@ private int yylex() throws IOException {
if (lex_strterm != null) {
int tok = lex_strterm.parseString(this, src);

if (tok == Tokens.tSTRING_END && (peek('"', -1) || peek('\'', -1))) {
if (tok == Tokens.tSTRING_END && (lex_strterm.getFlags() & STR_FUNC_LABEL) != 0) {
if ((isLexState(lex_state, EXPR_BEG|EXPR_ENDFN) && !conditionState.isInState() ||
isARG()) && isLabelSuffix()) {
nextc();
1 change: 1 addition & 0 deletions core/src/main/java/org/jruby/ext/ripper/StrTerm.java
Original file line number Diff line number Diff line change
@@ -32,5 +32,6 @@
/**
*/
public abstract class StrTerm {
public abstract int getFlags();
public abstract int parseString(RipperLexer lexer, LexerSource src) throws java.io.IOException;
}
4 changes: 4 additions & 0 deletions core/src/main/java/org/jruby/ext/ripper/StringTerm.java
Original file line number Diff line number Diff line change
@@ -54,6 +54,10 @@ public StringTerm(int flags, int begin, int end) {
this.nest = 0;
}

public int getFlags() {
return flags;
}

protected ByteList createByteList(RipperLexer lexer) {
return new ByteList(new byte[]{}, lexer.getEncoding());
}
29 changes: 29 additions & 0 deletions core/src/main/java/org/jruby/lexer/LexingCommon.java
Original file line number Diff line number Diff line change
@@ -606,6 +606,35 @@ public boolean update_heredoc_indent(int c) {
return false;
}

public void validateFormalIdentifier(String identifier) {
char first = identifier.charAt(0);

if (Character.isUpperCase(first)) {
compile_error("formal argument cannot be a constant");
}

switch(first) {
case '@':
if (identifier.charAt(1) == '@') {
compile_error("formal argument cannot be a class variable");
} else {
compile_error("formal argument cannot be an instance variable");
}
break;
case '$':
compile_error("formal argument cannot be a global variable");
break;
default:
// This mechanism feels a tad dicey but at this point we are dealing with a valid
// method name at least so we should not need to check the entire string...
char last = identifier.charAt(identifier.length() - 1);

if (last == '=' || last == '?' || last == '!') {
compile_error("formal argument must be local variable");
}
}
}

/**
* Value of last token (if it is a token which has a value).
*
4 changes: 4 additions & 0 deletions core/src/main/java/org/jruby/lexer/yacc/HeredocTerm.java
Original file line number Diff line number Diff line change
@@ -71,6 +71,10 @@ public HeredocTerm(ByteList marker, int func, int nth, int line, ByteList lastLi
this.lastLine = lastLine;
}

public int getFlags() {
return flags;
}

protected int error(RubyLexer lexer, int len, ByteList str, ByteList eos) {
lexer.compile_error("can't find string \"" + eos.toString() + "\" anywhere before EOF");
return -1;
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/lexer/yacc/RubyLexer.java
Original file line number Diff line number Diff line change
@@ -821,7 +821,7 @@ private int yylex() throws IOException {
if (lex_strterm != null) {
int tok = lex_strterm.parseString(this);

if (tok == Tokens.tSTRING_END && (yaccValue.equals("\"") || yaccValue.equals("'"))) {
if (tok == Tokens.tSTRING_END && (lex_strterm.getFlags() & STR_FUNC_LABEL) != 0) {
if ((isLexState(lex_state, EXPR_BEG|EXPR_ENDFN) && !conditionState.isInState() ||
isARG()) && isLabelSuffix()) {
nextc();
1 change: 1 addition & 0 deletions core/src/main/java/org/jruby/lexer/yacc/StrTerm.java
Original file line number Diff line number Diff line change
@@ -28,5 +28,6 @@
package org.jruby.lexer.yacc;

public abstract class StrTerm {
public abstract int getFlags();
public abstract int parseString(RubyLexer lexer) throws java.io.IOException;
}
4 changes: 4 additions & 0 deletions core/src/main/java/org/jruby/lexer/yacc/StringTerm.java
Original file line number Diff line number Diff line change
@@ -58,6 +58,10 @@ public StringTerm(int flags, int begin, int end) {
this.nest = 0;
}

public int getFlags() {
return flags;
}

protected ByteList createByteList(RubyLexer lexer) {
ByteList bytelist = new ByteList(15);
bytelist.setEncoding(lexer.getEncoding());
5 changes: 3 additions & 2 deletions core/src/main/java/org/jruby/parser/ParserSupport.java
Original file line number Diff line number Diff line change
@@ -953,6 +953,7 @@ public Node literal_concat(ISourcePosition position, Node head, Node tail) {
if (lexer.getHeredocIndent() > 0) {
if (head instanceof StrNode) {
head = createDStrNode(head.getPosition()).add(head);
return list_append(head, tail);
} else if (head instanceof DStrNode) {
return list_append(head, tail);
}
@@ -973,7 +974,7 @@ public Node literal_concat(ISourcePosition position, Node head, Node tail) {
return ((ListNode) head).add(tail);

} else if (tail instanceof DStrNode) {
if (head instanceof StrNode){
if (head instanceof StrNode) { // Str + oDStr -> Dstr(Str, oDStr.contents)
DStrNode newDStr = new DStrNode(head.getPosition(), ((DStrNode) tail).getEncoding());
newDStr.add(head);
newDStr.addAll(tail);
@@ -1186,7 +1187,7 @@ public ArgumentNode arg_var(String name) {
}

public String formal_argument(String identifier) {
if (!is_local_id(identifier) || Character.isUpperCase(identifier.charAt(0))) yyerror("formal argument must be local variable");
lexer.validateFormalIdentifier(identifier);

return shadowing_lvar(identifier);
}
19 changes: 1 addition & 18 deletions test/mri/excludes/TestSyntax.rb
Original file line number Diff line number Diff line change
@@ -2,29 +2,12 @@
exclude :test_constant_reassignment_nested, "needs investigation"
exclude :test_constant_reassignment_toplevel, "needs investigation"
exclude :test_defined_empty_argument, "needs investigation"
exclude :test_do_block_in_call_args, "needs investigation"
exclude :test_do_block_in_cmdarg, "needs investigation"
exclude :test_do_block_in_cmdarg_begin, "needs investigation"
exclude :test_duplicated_when, "needs investigation"
exclude :test_error_message_encoding, "#2127"
exclude :test_integer_suffix, "needs investigation"
exclude :test_keyword_duplicated_splat, "fix when dealing w/ mixed sym/str keys"
exclude :test_keyword_self_reference, "#2124"
exclude :test_keyword_splat, "needs investigation"
exclude :test_lineno_after_heredoc, "needs investigation"
exclude :test_optional_self_reference, "#2124"
exclude :test_script_lines, "needs investigation"
exclude :test_syntax_ext, "non-existing directory"
exclude :test_syntax_lib, "non-existing directory"
exclude :test_syntax_sample, "non-existing directory"
exclude :test_syntax_test, "non-existing directory"
exclude :test_unexpected_fraction, "#2126"
exclude :test_value_of_def, "process launching issues"
exclude :test_warn_balanced, "needs investigation"
exclude :test_warn_grouped_expression, "needs investigation"
exclude :test_warn_unreachable, "needs investigation"
exclude :test_warning_for_cr, "needs investigation"
exclude :test_bad_kwarg, "needs investigation"
exclude :test_do_block_in_lambda, "needs investigation"
exclude :test_invalid_next, "needs investigation"
exclude :test_null_range_cmdarg, "needs investigation"
exclude :test_too_big_nth_ref, "needs investigation"