Skip to content

Commit

Permalink
Rescue from exceptions raised by #name (#899)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
monkeyWzr authored Mar 14, 2024
1 parent 29901e4 commit 35b87cf
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/irb/completion.rb
Original file line number Diff line number Diff line change
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 35b87cf

Please sign in to comment.