Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should raise ParsingError instead of NoMethodError #1675

Merged
merged 1 commit into from
Dec 14, 2023

Conversation

ksss
Copy link
Collaborator

@ksss ksss commented Dec 14, 2023

I found a record type pattern that resulted in a NoMethodError instead of a ParsingError, so I fixed it.

RBS::Parser.parse_type("{1?: 1}")
#=> /Users/ksss/.rbenv/versions/3.3.0-rc1/lib/ruby/gems/3.3.0+0/gems/rbs-3.3.2/lib/rbs/parser_aux.rb:7:in `_parse_type': undefined method `literal' for an instance of RBS::Types::Optional (NoMethodError)

      _parse_type(buf, range.begin || 0, range.end || buf.last_position, variables, require_eof)
      ^^^^^^^^^^^

It seems that if the record key starts with Symbol, String, Integer, true, or false, and is not a literal type, the literal method cannot be called, resulting in a NoMethodError.

Although it is not impossible to optimize the code for each token in detail, I think that using parse_simple is a reasonable fix.

@soutaro soutaro added this to the RBS 3.4 milestone Dec 14, 2023
Copy link
Member

@soutaro soutaro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! 🙏

@soutaro soutaro added this pull request to the merge queue Dec 14, 2023
Merged via the queue into ruby:master with commit d84612d Dec 14, 2023
24 checks passed
@ksss ksss deleted the parse-record-lit branch December 14, 2023 02:20
soutaro added a commit that referenced this pull request Dec 20, 2023
This reverts commit d84612d, reversing
changes made to 4eb84e2.
@soutaro soutaro added the Released PRs already included in the released version label Dec 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Released PRs already included in the released version
Development

Successfully merging this pull request may close these issues.

2 participants