Skip to content

Prism::Translation::Parser incompatibility with Parser::Diagnostic #2454

@koic

Description

@koic

An incompatibility issue in handling Ruby warnings has been identified between the Parser gem and Prism.

Here is an example of the difference in emulation for the following warnings:

$ ruby -cwe "do_something *array"
-e:1: warning: `*' interpreted as argument prefix
Syntax OK

Below is the Gemfile common to expected and actual:

$ cat Gemfile
# frozen_string_literal: true

source "https://rubygems.org"

gem 'prism'
gem 'rubocop'

Expected Behavior

There is an expectation for a diagnostics array to return, similar to that provided by Parser gem:

$ bundle exec ruby -rprism/translation/parser/rubocop -ve "p RuboCop::AST::ProcessedSource.new('do_something *array', 3.3).diagnostics"
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [x86_64-darwin22]
[#<Parser::Diagnostic:0x000000011f05c7b8 @level=:warning, @reason=:ambiguous_prefix, @arguments={:prefix=>"*"}, @location=#<Parser::Source::Range (string) 13...14>, @highlights=[]>]

Actual Behavior

When using Prism as the backend, the diagnostics return value becomes an empty array:

$ bundle exec ruby -rprism/translation/parser/rubocop -ve "p RuboCop::AST::ProcessedSource.new('do_something *array', 80_82_73_83_77.33).diagnostics"
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [x86_64-darwin22]
[]

It is expected to return the same result as 3.3, even when the argument is 80_82_73_83_77.33.

Background

This difference in behavior was detected while I was working on the Prism integration, due to a failing test within RuboCop AST:
https://github.com/rubocop/rubocop-ast/blob/v1.30.0/spec/rubocop/ast/processed_source_spec.rb#L189-L197

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingrubocopErrors that affect Rubocop use of Prism

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions