Actions
Bug #13987
closedRipper.sexp named parameters with default values, double splat parameter
Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.5.0dev (2017-10-07 trunk 60132) [x64-mingw32]
Backport:
Description
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
:
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
Updated by nobu (Nobuyoshi Nakada) over 6 years ago
- Status changed from Open to Closed
Applied in changeset trunk|r60138.
parse.y: fix a typo
- parse.y (f_kw): fix typo. needs the argument value, not the
label twice. [ruby-core:83174] [Bug #13987]
Updated by nobu (Nobuyoshi Nakada) over 6 years ago
The latter is the change by [Feature #12387].
Updated by nobu (Nobuyoshi Nakada) over 6 years ago
- Backport changed from 2.3: UNKNOWN, 2.4: UNKNOWN to 2.3: DONTNEED, 2.4: DONTNEED
Actions
Like0
Like0Like0Like0