File tree Expand file tree Collapse file tree 2 files changed +48
-2
lines changed Expand file tree Collapse file tree 2 files changed +48
-2
lines changed Original file line number Diff line number Diff line change @@ -210,15 +210,17 @@ def resolve_loc(locations)
210
210
end
211
211
return unless resolved_loc
212
212
213
+ resolved_loc_path = resolved_loc . absolute_path || resolved_loc . path
214
+
213
215
# Find the location of the last frame in this file to get the most accurate line number.
214
- resolved_loc = locations . find { |loc | loc . absolute_path == resolved_loc . absolute_path }
216
+ resolved_loc = locations . find { |loc | loc . absolute_path == resolved_loc_path }
215
217
return unless resolved_loc
216
218
217
219
# If the last operation was a `require`, and we have no more frames,
218
220
# we are probably dealing with a C-method.
219
221
return if locations . first &.label == "require"
220
222
221
- file = resolved_loc . absolute_path || ""
223
+ file = resolved_loc . absolute_path || resolved_loc . path || ""
222
224
223
225
SourceLocation . from_loc ( [ file , resolved_loc . lineno ] )
224
226
end
Original file line number Diff line number Diff line change @@ -4112,6 +4112,50 @@ module Container::FooModule; end
4112
4112
assert_equal ( output , compile )
4113
4113
end
4114
4114
4115
+ it "handles class_eval created methods" do
4116
+ add_ruby_file ( "container.rb" , <<~'RUBY' )
4117
+ class Foo
4118
+ class_eval <<~EOF
4119
+ def foo; end
4120
+ def bar; end
4121
+ EOF
4122
+
4123
+ class_eval <<~EOF, __FILE__, __LINE__ + 1
4124
+ def baz; end
4125
+ def qux; end
4126
+ EOF
4127
+
4128
+ # Somehow defining methods in a loop triggers a different behavior
4129
+ # in backtrace locations where the absolute path ends up being `nil`.
4130
+ %w[string integer float boolean date datetime decimal money].each do |attr_type|
4131
+ class_eval <<-EOV, __FILE__, __LINE__ + 1
4132
+ def #{attr_type}
4133
+ end
4134
+ EOV
4135
+ end
4136
+ end
4137
+ RUBY
4138
+
4139
+ output = template ( <<~RBI )
4140
+ class Foo
4141
+ def bar; end
4142
+ def baz; end
4143
+ def boolean; end
4144
+ def date; end
4145
+ def datetime; end
4146
+ def decimal; end
4147
+ def float; end
4148
+ def foo; end
4149
+ def integer; end
4150
+ def money; end
4151
+ def qux; end
4152
+ def string; end
4153
+ end
4154
+ RBI
4155
+
4156
+ assert_equal ( output , compile )
4157
+ end
4158
+
4115
4159
it "includes comment documentation from sources when doc is true" do
4116
4160
add_ruby_file ( "foo.rb" , <<~RUBY )
4117
4161
# frozen_string_literal: true
You can’t perform that action at this time.
0 commit comments