Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix info c <exp> when <exp> doesn't return a constant #952

Merged
merged 2 commits into from
May 4, 2023
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
15 changes: 10 additions & 5 deletions lib/debug/thread_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -607,12 +607,17 @@ def iter_consts c, names = {}

def get_consts expr = nil, only_self: false, &block
if expr && !expr.empty?
_self = frame_eval(expr)
if M_KIND_OF_P.bind_call(_self, Module)
iter_consts _self, &block
return
begin
_self = frame_eval(expr, re_raise: true)
rescue Exception => e
# ignore
else
raise "#{_self.inspect} (by #{expr}) is not a Module."
if M_KIND_OF_P.bind_call(_self, Module)
iter_consts _self, &block
return
else
puts "#{_self.inspect} (by #{expr}) is not a Module."
end
end
elsif _self = current_frame&.self
cs = {}
Expand Down
30 changes: 30 additions & 0 deletions test/console/info_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,36 @@ def test_info_constant_with_expression
type "c"
end
end

def test_info_constant_with_expression_errors
debug_code(program) do
type "b 31"
type "c"
assert_line_num 31

type "info constants foo"
assert_line_text([
/eval error: undefined local variable or method `foo' for main/,
])

type "c"
end
end

def test_info_constant_with_non_module_expression
debug_code(program) do
type "b 31"
type "c"
assert_line_num 31

type "info constants 3"
assert_line_text([
/3 \(by 3\) is not a Module./
])

type "c"
end
end
end

class InfoIvarsTest < ConsoleTestCase
Expand Down