ruby / rbs

Type Signature for Ruby
Other
1.94k stars 211 forks source link

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

Open sinsoku opened 1 year ago

sinsoku commented 1 year ago

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)
pocke commented 1 year ago

1316 will solve this problem by fixing RBS::Writer. But this PR doesn't change the behavior of the parser.