Permalink
Browse files

Correctly raise TypeError even if nil or false is given

  • Loading branch information...
1 parent b85c893 commit c6c68247840967986d3000994973373db9a98d8a @ryoqun ryoqun committed Oct 2, 2012
Showing with 10 additions and 3 deletions.
  1. +9 −2 kernel/bootstrap/thread.rb
  2. +1 −1 kernel/delta/kernel.rb
@@ -234,7 +234,7 @@ def join_inner(timeout = undefined)
end
private :join_inner
- def raise(exc=$!, msg=nil, trace=nil)
+ def raise(exc=undefined, msg=nil, trace=nil)
Rubinius.lock(self)
unless @alive
@@ -243,11 +243,18 @@ def raise(exc=$!, msg=nil, trace=nil)
end
begin
+ if exc.equal?(undefined)
+ no_argument = true
+ exc = $!
+ end
+
if exc.respond_to? :exception
exc = exc.exception msg
Kernel.raise TypeError, 'exception class/object expected' unless Exception === exc
exc.set_backtrace trace if trace
- elsif exc.kind_of? String or !exc
+ elsif no_argument
+ exc = RuntimeError.exception nil
+ elsif exc.kind_of? String
exc = RuntimeError.exception exc
else
Kernel.raise TypeError, 'exception class/object expected'
@@ -18,7 +18,7 @@ def raise(exc=undefined, msg=undefined, ctx=nil)
exc = exc.exception msg
end
raise ::TypeError, 'exception class/object expected' unless exc.kind_of?(::Exception)
- elsif exc.kind_of? String or !exc
+ elsif exc.kind_of? String
exc = ::RuntimeError.exception exc
else
raise ::TypeError, 'exception class/object expected'

0 comments on commit c6c6824

Please sign in to comment.