rbs icon indicating copy to clipboard operation
rbs copied to clipboard

RBS::ParsingError: Syntax error: optional keyword argument type is expected, token=`(` (pLPAREN)

Open HoneyryderChuck opened this issue 3 years ago • 1 comments

I'm having the following error correcting the folllowing optparse signature:

- | (String params, Class | Array[String] | Hash[Symbol, untyped] | Regexp obj, ?String desc) ?{ (*untyped) -> untyped } -> untyped
+ | (*String params, Class | Array[String] | Hash[Symbol, untyped] | Regexp obj, ?String desc) ?{ (*untyped) -> untyped } -> untyped

rbs will throw the following error when parsing:

RBS::ParsingError: stdlib/optparse/0/optparse.rbs:697:33...697:34: Syntax error: optional keyword argument type is expected, token=`(` (pLPAREN)
/Users/tiagocardoso/dev/rbs/lib/rbs/parser_aux.rb:12:in `_parse_signature'
/Users/tiagocardoso/dev/rbs/lib/rbs/parser_aux.rb:12:in `parse_signature'
test/rbs/writer_test.rb:236:in `block in test_smoke'

I think that the parser can't deal with optional rest arguments, when splatting is used.

HoneyryderChuck avatar Jul 27 '22 09:07 HoneyryderChuck

This is an intended behavior, because optional argument after splat is not supported in Ruby.

The semantics of method argument binding in RBS and Ruby are different. So, it may be possible, once we found a good semantics that works and can be implemented.

soutaro avatar Jul 27 '22 15:07 soutaro

Feel free to reopen this issue to continue the discussion.

soutaro avatar Sep 02 '22 03:09 soutaro

I'd keep this open, as this is valid ruby code that cannot be typed yet. But it's your call.

HoneyryderChuck avatar Sep 02 '22 06:09 HoneyryderChuck