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

Warning/error messages mismatching #2852

Closed
andrykonchin opened this issue May 31, 2024 · 6 comments
Closed

Warning/error messages mismatching #2852

andrykonchin opened this issue May 31, 2024 · 6 comments

Comments

@andrykonchin
Copy link
Member

andrykonchin commented May 31, 2024

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:

  • "expected a delimiter after the patterns of an in clause"
  • "unexpected '+', ignoring it"

CRuby returns the following error message:

syntax error, unexpected '+', expecting `then' or ';' or '\n'
in 1 + 1
     ^
@andrykonchin
Copy link
Member Author

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
Copy link
Collaborator

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
Copy link
Member Author

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

@eregon
Copy link
Member

eregon commented Jun 3, 2024

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
Copy link
Member Author

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

@kddnewton
Copy link
Collaborator

Perfect, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants