Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions pathname_builtin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -312,12 +312,12 @@ def sub_ext(repl)

if File::ALT_SEPARATOR
# Separator list string.
SEPARATOR_LIST = "#{Regexp.quote File::ALT_SEPARATOR}#{Regexp.quote File::SEPARATOR}"
SEPARATOR_LIST = Regexp.quote "#{File::ALT_SEPARATOR}#{File::SEPARATOR}"
# Regexp that matches a separator.
SEPARATOR_PAT = /[#{SEPARATOR_LIST}]/
else
SEPARATOR_LIST = "#{Regexp.quote File::SEPARATOR}"
SEPARATOR_PAT = /#{Regexp.quote File::SEPARATOR}/
SEPARATOR_LIST = Regexp.quote File::SEPARATOR
SEPARATOR_PAT = /#{SEPARATOR_LIST}/
end

if File.dirname('A:') == 'A:.' # DOSish drive letter
Expand Down Expand Up @@ -383,7 +383,7 @@ def split_names(path) # :nodoc:
def prepend_prefix(prefix, relpath) # :nodoc:
if relpath.empty?
File.dirname(prefix)
elsif /#{SEPARATOR_PAT}/o.match?(prefix)
elsif SEPARATOR_PAT.match?(prefix)
prefix = File.dirname(prefix)
prefix = File.join(prefix, "") if File.basename(prefix + 'a') != 'a'
prefix + relpath
Expand Down Expand Up @@ -434,7 +434,7 @@ def cleanpath_aggressive # :nodoc:
end
end
pre.tr!(File::ALT_SEPARATOR, File::SEPARATOR) if File::ALT_SEPARATOR
if /#{SEPARATOR_PAT}/o.match?(File.basename(pre))
if SEPARATOR_PAT.match?(File.basename(pre))
names.shift while names[0] == '..'
end
self.class.new(prepend_prefix(pre, File.join(*names)))
Expand Down Expand Up @@ -483,7 +483,7 @@ def cleanpath_conservative # :nodoc:
names.unshift base if base != '.'
end
pre.tr!(File::ALT_SEPARATOR, File::SEPARATOR) if File::ALT_SEPARATOR
if /#{SEPARATOR_PAT}/o.match?(File.basename(pre))
if SEPARATOR_PAT.match?(File.basename(pre))
names.shift while names[0] == '..'
end
if names.empty?
Expand Down Expand Up @@ -528,7 +528,7 @@ def mountpoint?
# pathnames which points to roots such as <tt>/usr/..</tt>.
#
def root?
chop_basename(@path) == nil && /#{SEPARATOR_PAT}/o.match?(@path)
chop_basename(@path) == nil && SEPARATOR_PAT.match?(@path)
end

# Predicate method for testing whether a path is absolute.
Expand Down Expand Up @@ -698,7 +698,7 @@ def plus(path1, path2) # -> path # :nodoc:
basename_list2.shift
end
r1 = chop_basename(prefix1)
if !r1 && (r1 = /#{SEPARATOR_PAT}/o.match?(File.basename(prefix1)))
if !r1 && (r1 = SEPARATOR_PAT.match?(File.basename(prefix1)))
while !basename_list2.empty? && basename_list2.first == '..'
index_list2.shift
basename_list2.shift
Expand Down
27 changes: 27 additions & 0 deletions test/ruby/test_exception.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1525,4 +1525,31 @@ def detailed_message(**)
assert_in_out_err(%W[-r#{lib} #{main}], "", [], [:*, "\n""path=#{main}\n", :*])
end
end

class Ex; end

def test_exception_message_for_unexpected_implicit_conversion_type
a = Ex.new
def self.x(a) = nil

assert_raise_with_message(TypeError, "no implicit conversion of TestException::Ex into Hash") do
x(**a)
end
assert_raise_with_message(TypeError, "no implicit conversion of TestException::Ex into Proc") do
x(&a)
end

def a.to_a = 1
def a.to_hash = 1
def a.to_proc = 1
assert_raise_with_message(TypeError, "can't convert TestException::Ex to Array (TestException::Ex#to_a gives Integer)") do
x(*a)
end
assert_raise_with_message(TypeError, "can't convert TestException::Ex to Hash (TestException::Ex#to_hash gives Integer)") do
x(**a)
end
assert_raise_with_message(TypeError, "can't convert TestException::Ex to Proc (TestException::Ex#to_proc gives Integer)") do
x(&a)
end
end
end
2 changes: 1 addition & 1 deletion test/ruby/test_struct.rb
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ def test_named_structs_are_not_rooted
Struct.send(:remove_const, :A)
end

1_000.times(&code)
10_000.times(&code)
PREP
50_000.times(&code)
CODE
Expand Down
5 changes: 2 additions & 3 deletions tool/rbinstall.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,6 @@ def (bins = []).add(name)
prepare "manpages", mandir, ([] | mdocs.collect {|mdoc| mdoc[/\d+$/]}).sort.collect {|sec| "man#{sec}"}

mantype, suffix, compress = Compressors.for($mantype)
mandir = File.join(mandir, "man")
has_goruby = File.exist?(goruby_install_name+exeext)
require File.join(srcdir, "tool/mdoc2man.rb") if /\Adoc\b/ !~ mantype
mdocs.each do |mdoc|
Expand All @@ -1031,8 +1030,8 @@ def (bins = []).add(name)
next unless has_goruby
end

destdir = mandir + (section = mdoc[/\d+$/])
destname = ruby_install_name.sub(/ruby/, base.chomp(".#{section}"))
destdir = File.join(mandir, "man" + (section = mdoc[/\d+$/]))
destname = $script_installer.transform(base.chomp(".#{section}"))
destfile = File.join(destdir, "#{destname}.#{section}")

if /\Adoc\b/ =~ mantype or !mdoc_file?(mdoc)
Expand Down
14 changes: 11 additions & 3 deletions vm_args.c
Original file line number Diff line number Diff line change
Expand Up @@ -1045,9 +1045,17 @@ vm_to_proc(VALUE proc)
}

if (NIL_P(b) || !rb_obj_is_proc(b)) {
rb_raise(rb_eTypeError,
"wrong argument type %s (expected Proc)",
rb_obj_classname(proc));
if (me) {
VALUE cname = rb_obj_class(proc);
rb_raise(rb_eTypeError,
"can't convert %"PRIsVALUE" to Proc (%"PRIsVALUE"#to_proc gives %"PRIsVALUE")",
cname, cname, rb_obj_class(b));
}
else {
rb_raise(rb_eTypeError,
"no implicit conversion of %s into Proc",
rb_obj_classname(proc));
}
}
return b;
}
Expand Down