Skip to content

Commit

Permalink
[ruby/irb] Rescue from exceptions raised by #name
Browse files Browse the repository at this point in the history
(ruby/irb#899)

* Rescue from exceptions raised by #name

Irb might terminate if the class overwrites `name` and raise errors. This commit rescue irb from termination.

* fix for other unknown patterns

ruby/irb@35b87cf893
  • Loading branch information
monkeyWzr authored and matzbot committed Mar 14, 2024
1 parent 3822ca9 commit d10afe0
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/irb/completion.rb
Expand Up @@ -388,7 +388,7 @@ def retrieve_completion_data(input, bind:, doc_namespace:)

if doc_namespace
rec_class = rec.is_a?(Module) ? rec : rec.class
"#{rec_class.name}#{sep}#{candidates.find{ |i| i == message }}"
"#{rec_class.name}#{sep}#{candidates.find{ |i| i == message }}" rescue nil
else
select_message(receiver, message, candidates, sep)
end
Expand Down Expand Up @@ -418,7 +418,7 @@ def retrieve_completion_data(input, bind:, doc_namespace:)
vars = (bind.local_variables | bind.eval_instance_variables).collect{|m| m.to_s}
perfect_match_var = vars.find{|m| m.to_s == input}
if perfect_match_var
eval("#{perfect_match_var}.class.name", bind)
eval("#{perfect_match_var}.class.name", bind) rescue nil
else
candidates = (bind.eval_methods | bind.eval_private_methods | bind.local_variables | bind.eval_instance_variables | bind.eval_class_constants).collect{|m| m.to_s}
candidates |= ReservedWords
Expand Down

0 comments on commit d10afe0

Please sign in to comment.