diff --git a/core/errors.rbs b/core/errors.rbs index 523ee2435..2cc6af476 100644 --- a/core/errors.rbs +++ b/core/errors.rbs @@ -299,6 +299,36 @@ class NameError[T] < StandardError def receiver: () -> T? end +class NoMatchingPatternError < StandardError +end + +class NoMatchingPatternKeyError[M, K] < NoMatchingPatternError + # + # Construct a new `NoMatchingPatternKeyError` exception with the given message, + # matchee and key. + # + def initialize: (?string message, matchee: M, key: K) -> void + + # + # Return the matchee associated with this NoMatchingPatternKeyError exception. + # + def matchee: () -> M + + # + # Return the key caused this NoMatchingPatternKeyError exception. + # + def key: () -> K +end + # # Raised when memory allocation fails. # diff --git a/test/stdlib/NoMatchingPatternKeyError_test.rb b/test/stdlib/NoMatchingPatternKeyError_test.rb new file mode 100644 index 000000000..a41e3f941 --- /dev/null +++ b/test/stdlib/NoMatchingPatternKeyError_test.rb @@ -0,0 +1,35 @@ +require_relative "test_helper" + +class NoMatchingPatternKeyErrorSingletonTest < Test::Unit::TestCase + include TypeAssertions + + testing "singleton(::NoMatchingPatternKeyError)" + + + def test_new + assert_send_type "[Matchee, Key] (?::string message, matchee: Integer, key: Integer) -> ::NoMatchingPatternKeyError[Integer, Integer]", + NoMatchingPatternKeyError, :new, matchee: 123, key: 234 + end +end + +class NoMatchingPatternKeyErrorTest < Test::Unit::TestCase + include TypeAssertions + + testing "::NoMatchingPatternKeyError[Hash[Symbol, untyped], Symbol]" + + + def test_initialize + assert_send_type "(?::string message, matchee: Hash[Symbol, untyped], key: Symbol) -> void", + NoMatchingPatternKeyError.new(matchee: {a: 1}, key: :aa), :initialize, matchee: {a: 1}, key: :aa + end + + def test_matchee + assert_send_type "() -> Hash[Symbol, untyped]", + NoMatchingPatternKeyError.new(matchee: {a: 1}, key: :aa), :matchee + end + + def test_key + assert_send_type "() -> Symbol", + NoMatchingPatternKeyError.new(matchee: {a: 1}, key: :aa), :key + end +end