Skip to content

Commit e15c7e8

Browse files
committed
Fix Kernel#raise when it's called with a String message and an extra argument and raise TypeError
1 parent 91f5943 commit e15c7e8

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

spec/ruby/shared/kernel/raise.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ def initialize
8888
-> { @object.raise(nil) }.should raise_error(TypeError, "exception class/object expected")
8989
end
9090

91+
it "raises a TypeError when passed a message and an extra argument" do
92+
-> { @object.raise("message", {cause: RuntimeError.new()}) }.should raise_error(TypeError, "exception class/object expected")
93+
end
94+
9195
it "raises TypeError when passed a non-Exception object but it responds to #exception method that doesn't return an instance of Exception class" do
9296
e = Object.new
9397
def e.exception

src/main/ruby/truffleruby/core/truffle/exception_operations.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def self.build_exception_for_raise(exc, msg)
2222

2323
exception_object_expected! unless Primitive.is_a?(exc, ::Exception)
2424
exc
25-
elsif Primitive.is_a?(exc, ::String)
25+
elsif Primitive.is_a?(exc, ::String) && Primitive.undefined?(msg)
2626
::RuntimeError.exception exc
2727
else
2828
exception_class_object_expected!

test/mri/excludes/TestException.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
exclude :test_marshal_circular_cause, "\"\\x04\\bo:\\x11RuntimeError\\b:\\tmesgI\\\"\\berr\\x06:\\x06ET:\\abt[\\x00:\\ncauseo:\\x0EException\\a;\\x060;\\b0\"."
1313
exclude :test_non_exception_cause, "Exception(TypeError) with message matches to /exception/."
1414
exclude :test_output_string_encoding, "<1> expected but was <0>."
15-
exclude :test_raise_with_cause, "[TypeError] exception expected, not #<RuntimeError: [Feature #8257]>."
1615
exclude :test_stackoverflow, "<no message> (java.lang.IndexOutOfBoundsException) from com.oracle.svm.core.jni.functions.JNIFunctions$NewObjectWithObjectArrayArgFunctionPointer.invoke(JNIFunctions.java:-1)"
1716
exclude :test_too_many_args_in_eval, "[SystemStackError] exception expected, not #<ArgumentError: wrong number of arguments (given 140000, expected 0..3)>."
1817
exclude :test_undef_Warning_warn, "[NoMethodError] exception expected, not #<NameError: undefined method `warn' for class `Module'>."

0 commit comments

Comments
 (0)