Skip to content

NoMatchingPatternError#=== doesn't match instance of NoMatchingPatternKeyError #9537

Description

@nevans

NoMatchingPatternError#=== doesn't match an instance of NoMatchingPatternKeyError, even though NoMatchingPatternError is the superclass of NoMatchingPatternKeyError.

This is the behavior I see from CRuby (3.3, 3.4, 4.0), tested in irb:

NoMatchingPatternError === NoMatchingPatternKeyError.new("message", matchee: :foo, key: :bar)
=> true

Here's what I see with RBENV_VERSION=jruby-10.0.5.0 irb

NoMatchingPatternError === NoMatchingPatternKeyError.new("message", matchee: :foo, key: :bar)
=> false

This is mostly relevant for rescue clause matching, e.g:

def foo(*args, **kwargs)
  case [*args, kwargs]
  in /\A(hi|hello)\z/, {world: COMPATIBLE_WORLDS}
    do the thing
  end
rescue NoMatchingPatternError # should match NoMatchingPatternKeyError, but doesn't
  raise ArgumentError, "etc, etc, ..."
end

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions