ruby / prism

Prism Ruby parser
https://ruby.github.io/prism/
MIT License
825 stars 139 forks source link

Warning/error messages mismatching #2852

Closed andrykonchin closed 4 months ago

andrykonchin commented 4 months ago

After recent update to the latest Prism we have two new failures in ruby/spec tests suite, related to a bit different warning/exception messages. So wondering if it's a known issue and 100% matching is supposed at all.

1

  it "warns if there are identical when clauses" do
    -> {
      eval <<~RUBY
        case 1
        when 2
          :foo
        when 2
          :bar
        end
      RUBY
    }.should complain(/warning: duplicated .when' clause with line \d+ is ignored/, verbose: true)
  end

Prism returns "'when' clause on line 4 duplicates 'when' clause on line 2 and is ignored"

2

  it "does not allow calculation or method calls in a pattern" do
    -> {
      eval <<~RUBY
        case 0
        in 1 + 1
          true
        end
      RUBY
    }.should raise_error(SyntaxError, /unexpected|expected a delimiter after the predicates of a `when` clause/)
  end

Prism returns two errors:

CRuby returns the following error message:

syntax error, unexpected '+', expecting `then' or ';' or '\n'
in 1 + 1
     ^
andrykonchin commented 4 months ago

It seems pretty expected to have multiple syntax errors returned if the parser is used as a tool. But wondering how CRuby will (or already does) decide on which error message to use. And we are supposed to use the same approach in TruffleRuby to be compatible.

kddnewton commented 4 months ago

For the first one, yeah I suppose I'm returning the Ruby 3.4 error message and not the Ruby 3.3 error message, so I can fix that. For the second one, yeah I would concatenate them before you check, it's not always going to be the first error.

andrykonchin commented 4 months ago

Got it, thank you! So feel free to close this issue if it isn't needed to track any planned changing.

eregon commented 4 months ago

For the first one I think it's alright to use the clearer 3.4 error message even with version 3.3, we can just adapt specs to accept both, it doesn't seem worth adding a condition in Prism for this.

andrykonchin commented 4 months ago

Right, the ruby/spec's tests were changed to expect Prism-specific messages as well.

kddnewton commented 4 months ago

Perfect, thanks!