prism icon indicating copy to clipboard operation
prism copied to clipboard

`NoMatchingPatternError` on hash + parenthesis omission

Open avlazarov opened this issue 7 months ago • 3 comments

Hey folks,

Been getting an odd NoMatchingPatternError on Ruby 3.4.3 and Prism 1.4.0 (same on latest main at 2cae3102e9dfa7b5e4c53a6d6c3c5554f6108387)

# script.rb
module A
  extend self

  def print(message:)
    puts message
  end
end

case ENV['COND']
in 'FOO'
  message = 'foo'

  A.print message:
in 'BAR'
  message = 'bar'

  A.print message:
end
→ RUBYOPT="--parser prism" COND="BAR" ruby script.rb
script.rb:13:in '<main>': "BAR": "FOO" === "BAR" does not return true (NoMatchingPatternError)

Additionally, matching both conditions

→ RUBYOPT="--parser prism" COND="FOO" ruby script.rb
foo
bar

No issues with parse.y

→ RUBYOPT="--parser parse.y" COND="BAR" ruby script.rb
bar
→ RUBYOPT="--parser parse.y" COND="FOO" ruby script.rb
foo

avlazarov avatar May 05 '25 11:05 avlazarov

Thanks for the report! I'll check it out

kddnewton avatar May 06 '25 11:05 kddnewton

I think the cause of this issue is:

Prism.parse_success? "print message: in 'BAR'"  # => false
Prism.parse_success? "A.print message: in 'BAR'"  # => true, should be false
Prism.parse_success? "A.print message:\nin 'BAR'"  # => true, should be false

and it is not fixed yet.

tompng avatar May 07 '25 05:05 tompng

You're absolutely right, I'll keep going. Thanks @tompng!

kddnewton avatar May 07 '25 11:05 kddnewton