Issue #13987 has been updated by nobu (Nobuyoshi Nakada).


The latter is the change by [Feature #12387].

----------------------------------------
Bug #13987: Ripper.sexp named parameters with default values, double splat parameter
https://bugs.ruby-lang.org/issues/13987#change-67116

* Author: MSP-Greg (Greg L)
* Status: Closed
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.5.0dev (2017-10-07 trunk 60132) [x64-mingw32]
* Backport: 2.3: UNKNOWN, 2.4: UNKNOWN
----------------------------------------
The following is the pertinent section from `Ripper.sexp("def hello(bln: true, int: 1, str: 'str', sym: :sym) end")`.  Info about default values is missing:

```
ruby 2.5.0dev (2017-10-07 trunk 60132) [x64-mingw32]

[[:@label, "bln:", [1, 10]], [:@label, "bln:", [1, 10]]]
[[:@label, "int:", [1, 21]], [:@label, "int:", [1, 21]]]
[[:@label, "str:", [1, 29]], [:@label, "str:", [1, 29]]]
[[:@label, "sym:", [1, 41]], [:@label, "sym:", [1, 41]]]


ruby 2.5.0dev (2017-10-02 trunk 60101) [x64-mingw32]

[[:@label, "bln:", [1, 10]], [:var_ref, [:@kw, "true", [1, 15]]]]
[[:@label, "int:", [1, 21]], [:@int, "1", [1, 26]]]
[[:@label, "str:", [1, 29]], [:string_literal, [:string_content, [:@tstring_content, "str", [1, 35]]]]]
[[:@label, "sym:", [1, 41]], [:symbol_literal, [:symbol, [:@ident, "sym", [1, 47]]]]]
```

I used the following test added to `test\ripper\test_sexp.rb`:

```ruby
  def test_named_with_default
    sexp = Ripper.sexp("def hello(bln: true, int: 1, str: 'str', sym: :sym) end")
    named = String.new
    search_sexp(:params, sexp)[5].each { |i| named << "#{i}\n" }  # join flattens
    exp = <<~SEXP.strip
      [[:@label, "bln:", [1, 10]], [:var_ref, [:@kw, "true", [1, 15]]]]
      [[:@label, "int:", [1, 21]], [:@int, "1", [1, 26]]]
      [[:@label, "str:", [1, 29]], [:string_literal, [:string_content, [:@tstring_content, "str", [1, 35]]]]]
      [[:@label, "sym:", [1, 41]], [:symbol_literal, [:symbol, [:@ident, "sym", [1, 47]]]]]
    SEXP
    assert_equal(exp, named.strip)
  end
```

Also, I assume it's a breaking change, but again with `Ripper.sexp("def hello(**opts) end")`

```
2.4.2
[:@ident, "opts", [1, 12]]

trunk
[:kwrest_param, [:@ident, "opts", [1, 12]]]
```

Thanks again,  Greg



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>