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

Parsing errors occur in null-byte character type definitions #1344

Closed
tmimura39 opened this issue May 27, 2023 · 2 comments · Fixed by #1685
Closed

Parsing errors occur in null-byte character type definitions #1344

tmimura39 opened this issue May 27, 2023 · 2 comments · Fixed by #1685
Labels
bug Something isn't working
Milestone

Comments

@tmimura39
Copy link

If a null-byte character (\u0000) is defined as a literal type, a parse error occurs.

# cat my_module.rb
class MyModule
  def self.string
    "\u0000"
  end
end

# rbs prototype rb my_module.rb -o sig --force
Processing `my_module.rb`...
  Generating RBS for `my_module.rb`...
    - Writing RBS to existing file `sig/my_module.rbs`...

# cat sig/my_module.rbs
class MyModule
  def self.string: () -> "\u0000"
end

# rbs -Isig validate --silent
/usr/local/bundle/gems/rbs-3.1.0/lib/rbs/parser_aux.rb:17:in `_parse_signature': sig/my_module.rbs:2:25...2:26: Syntax error: unexpected token for simple type, token=`"` (ErrorToken) (RBS::ParsingError)

    def self.string: () -> "\u0000"
                           ^

	from /usr/local/bundle/gems/rbs-3.1.0/lib/rbs/parser_aux.rb:17:in `parse_signature'
	from /usr/local/bundle/gems/rbs-3.1.0/lib/rbs/environment_loader.rb:146:in `block (2 levels) in each_signature'
	from /usr/local/bundle/gems/rbs-3.1.0/lib/rbs/file_finder.rb:13:in `each_file'
	from /usr/local/bundle/gems/rbs-3.1.0/lib/rbs/file_finder.rb:26:in `block in each_file'
	from /usr/local/bundle/gems/rbs-3.1.0/lib/rbs/file_finder.rb:25:in `each'
	from /usr/local/bundle/gems/rbs-3.1.0/lib/rbs/file_finder.rb:25:in `each_file'
	from /usr/local/bundle/gems/rbs-3.1.0/lib/rbs/environment_loader.rb:140:in `block in each_signature'
	from /usr/local/bundle/gems/rbs-3.1.0/lib/rbs/environment_loader.rb:130:in `block in each_dir'
	from /usr/local/bundle/gems/rbs-3.1.0/lib/rbs/environment_loader.rb:129:in `each'
	from /usr/local/bundle/gems/rbs-3.1.0/lib/rbs/environment_loader.rb:129:in `each_dir'
	from /usr/local/bundle/gems/rbs-3.1.0/lib/rbs/environment_loader.rb:137:in `each_signature'
	from /usr/local/bundle/gems/rbs-3.1.0/lib/rbs/environment_loader.rb:101:in `load'
	from /usr/local/bundle/gems/rbs-3.1.0/lib/rbs/environment.rb:172:in `block in from_loader'
	from <internal:kernel>:90:in `tap'
	from /usr/local/bundle/gems/rbs-3.1.0/lib/rbs/environment.rb:171:in `from_loader'
	from /usr/local/bundle/gems/rbs-3.1.0/lib/rbs/cli.rb:460:in `run_validate'
	from /usr/local/bundle/gems/rbs-3.1.0/lib/rbs/cli.rb:137:in `run'
	from /usr/local/bundle/gems/rbs-3.1.0/exe/rbs:7:in `<top (required)>'
	from /usr/local/bundle/bin/rbs:25:in `load'
	from /usr/local/bundle/bin/rbs:25:in `<main>'

This is also true for constant definitions.

# cat my_module.rb
class MyModule
  NULL_BYTE = "\u0000"
end

# rbs prototype rb my_module.rb -o sig --force
Processing `my_module.rb`...
  Generating RBS for `my_module.rb`...
    - Writing RBS to existing file `sig/my_module.rbs`...

# cat sig/my_module.rbs
class MyModule
  NULL_BYTE: "\u0000"
end

# rbs -Isig validate --silent
/usr/local/bundle/gems/rbs-3.1.0/lib/rbs/parser_aux.rb:17:in `_parse_signature': sig/my_module.rbs:2:13...2:14: Syntax error: unexpected token for simple type, token=`"` (ErrorToken) (RBS::ParsingError)

    NULL_BYTE: "\u0000"
               ^

	from /usr/local/bundle/gems/rbs-3.1.0/lib/rbs/parser_aux.rb:17:in `parse_signature'
	from /usr/local/bundle/gems/rbs-3.1.0/lib/rbs/environment_loader.rb:146:in `block (2 levels) in each_signature'
	from /usr/local/bundle/gems/rbs-3.1.0/lib/rbs/file_finder.rb:13:in `each_file'
	from /usr/local/bundle/gems/rbs-3.1.0/lib/rbs/file_finder.rb:26:in `block in each_file'
	from /usr/local/bundle/gems/rbs-3.1.0/lib/rbs/file_finder.rb:25:in `each'
	from /usr/local/bundle/gems/rbs-3.1.0/lib/rbs/file_finder.rb:25:in `each_file'
	from /usr/local/bundle/gems/rbs-3.1.0/lib/rbs/environment_loader.rb:140:in `block in each_signature'
	from /usr/local/bundle/gems/rbs-3.1.0/lib/rbs/environment_loader.rb:130:in `block in each_dir'
	from /usr/local/bundle/gems/rbs-3.1.0/lib/rbs/environment_loader.rb:129:in `each'
	from /usr/local/bundle/gems/rbs-3.1.0/lib/rbs/environment_loader.rb:129:in `each_dir'
	from /usr/local/bundle/gems/rbs-3.1.0/lib/rbs/environment_loader.rb:137:in `each_signature'
	from /usr/local/bundle/gems/rbs-3.1.0/lib/rbs/environment_loader.rb:101:in `load'
	from /usr/local/bundle/gems/rbs-3.1.0/lib/rbs/environment.rb:172:in `block in from_loader'
	from <internal:kernel>:90:in `tap'
	from /usr/local/bundle/gems/rbs-3.1.0/lib/rbs/environment.rb:171:in `from_loader'
	from /usr/local/bundle/gems/rbs-3.1.0/lib/rbs/cli.rb:460:in `run_validate'
	from /usr/local/bundle/gems/rbs-3.1.0/lib/rbs/cli.rb:137:in `run'
	from /usr/local/bundle/gems/rbs-3.1.0/exe/rbs:7:in `<top (required)>'
	from /usr/local/bundle/bin/rbs:25:in `load'
	from /usr/local/bundle/bin/rbs:25:in `<main>'

Is it a bug in the parser?
Or is it an incorrect way of defining the null-byte character type (prototype bug)?

@soutaro soutaro added the bug Something isn't working label May 29, 2023
@soutaro soutaro added this to the RBS 3.2 milestone May 29, 2023
@pocke
Copy link
Member

pocke commented Jun 8, 2023

#1316 will fix this problem by updating RBS::Writer.

@soutaro soutaro modified the milestones: RBS 3.2, RBS 3.3 Aug 17, 2023
@soutaro soutaro modified the milestones: RBS 3.3, RBS 3.4 Nov 21, 2023
@soutaro soutaro mentioned this issue Dec 18, 2023
@soutaro
Copy link
Member

soutaro commented Dec 21, 2023

Fixed in #1685

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

Successfully merging a pull request may close this issue.

3 participants