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

Method name with non-ASCII characters #453

Closed
pocke opened this issue Oct 30, 2020 · 2 comments
Closed

Method name with non-ASCII characters #453

pocke opened this issue Oct 30, 2020 · 2 comments
Assignees
Milestone

Comments

@pocke
Copy link
Member

pocke commented Oct 30, 2020

Ruby allows you to define a method with non-ASCII characters, but RBS doesn't.

The following code in Ruby is valid.

def こんにちは
end

But RBS raises an error with the following RBS code.

# It is invalid as RBS
class A
  def こんにちは: () -> untyped
end
$ rbs parse test.rbs
parser.y:1373:in `next_token': Unexpected token: こんに�... (RuntimeError)
	from (eval):3:in `_racc_do_parse_c'
	from (eval):3:in `do_parse'
	from parser.y:1108:in `parse_signature'
	from /home/pocke/.rbenv/versions/trunk/lib/ruby/gems/3.0.0/gems/rbs-0.14.0/lib/rbs/cli.rb:739:in `block (2 levels) in run_parse'
	from /home/pocke/.rbenv/versions/trunk/lib/ruby/gems/3.0.0/gems/rbs-0.14.0/lib/rbs/environment_loader.rb:81:in `each_signature'
	from /home/pocke/.rbenv/versions/trunk/lib/ruby/gems/3.0.0/gems/rbs-0.14.0/lib/rbs/cli.rb:738:in `block in run_parse'
	from /home/pocke/.rbenv/versions/trunk/lib/ruby/gems/3.0.0/gems/rbs-0.14.0/lib/rbs/cli.rb:736:in `each'
	from /home/pocke/.rbenv/versions/trunk/lib/ruby/gems/3.0.0/gems/rbs-0.14.0/lib/rbs/cli.rb:736:in `run_parse'
	from /home/pocke/.rbenv/versions/trunk/lib/ruby/gems/3.0.0/gems/rbs-0.14.0/lib/rbs/cli.rb:98:in `run'
	from /home/pocke/.rbenv/versions/trunk/lib/ruby/gems/3.0.0/gems/rbs-0.14.0/exe/rbs:7:in `<top (required)>'
	from /home/pocke/.rbenv/versions/trunk/bin/rbs:23:in `load'
	from /home/pocke/.rbenv/versions/trunk/bin/rbs:23:in `<main>'

I actually define some method in Japanese, so rbs prototype rb generates RBSs with Japanese method name, and they're not valid.
We can define a method with non-ASCII, so I think RBS should allow also.

And, I guess RBS has the same problem for other identifiers, such as class, constants, etc.

@soutaro soutaro added this to the Ruby 3.0 milestone Nov 1, 2020
@soutaro soutaro self-assigned this Nov 1, 2020
@soutaro
Copy link
Member

soutaro commented Nov 1, 2020

A workaround is quoting the method name.

class A
  def `こんにちは`: () -> void
end

(I know it should parse without quoting because it's incompatible with Ruby.)

@soutaro
Copy link
Member

soutaro commented Dec 24, 2020

RBS still doesn't allow writing こんにちは as a method name in .rbs files, but it allows writing it with quotes. And RBS::Writer also supports it. (#537)

So, closing this issue for Ruby 3.

@soutaro soutaro closed this as completed Dec 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants