ruby / ruby/rbs

`rbs prototype rb` generates wrong definitions for files including "#$"

Open
#1,348 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Ruby
Stars
2.2k
Forks
256
Avg merge
6d 17h
Merged PRs (30d)
37

Description

rbs generates a definition that causes a syntax error if the file includes '#$'.

Steps to reproduce

$ cat foo.rb
class A
  X = '#$'
end

$ rbs prototype rb foo.rb > foo.rbs

$ cat foo.rbs
class A
  X: "\#$"
end

$ rbs parse foo.rbs
foo.rbs:2:5...2:6: Syntax error: unexpected token for simple type, token=`"` (ErrorToken)

System Information

$ ruby --version
ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [arm64-darwin21]

$ rbs --version
rbs 3.1.0

Notes

I report that the error did not occur in v2.5.1, but did occur in v2.6.0.

$ rbs _2.5.1_ parse foo.rbs

$ rbs _2.6.0_ parse foo.rbs
foo.rbs:2:5...2:6: Syntax error: unexpected token for simple type, token=`"` (ErrorToken)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with the shown rbs prototype rb foo.rb and rbs parse foo.rbs commands, then trace the prototype rb implementation and its tests. Add a regression case for a Ruby string containing '#$'; done means the generated definition parses successfully and preserves the intended value.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
cli, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.