@@ -156,47 +156,78 @@ function methods_by_execution!(@nospecialize(recurse), methodinfo, docexprs, fra
156
156
pc, pc3 = ret
157
157
# Get the line number from the body
158
158
stmt3 = pc_expr (frame, pc3)
159
- bodycode = stmt3. args[end ]
160
- if ! isa (bodycode, CodeInfo)
161
- bodycode = @lookup (frame, bodycode)
159
+ lnn = nothing
160
+ if line_is_decl
161
+ sigcode = @lookup (frame, stmt3. args[2 ])
162
+ lnn = sigcode[end ]
163
+ if ! isa (lnn, LineNumberNode)
164
+ lnn = nothing
165
+ end
162
166
end
163
- if isa (bodycode, CodeInfo)
164
- lnn = bodycode. linetable[1 ]
165
- if lnn. line == 0 && lnn. file == :none && length (bodycode. code) > 1
166
- # This may be a kwarg method. Mimic LoweredCodeUtils.bodymethod,
167
- # except without having a method
168
- stmt = bodycode. code[end - 1 ]
169
- if isa (stmt, Expr) && length (stmt. args) > 1
170
- a = stmt. args[1 ]
171
- hasself = any (i-> LoweredCodeUtils. is_self_call (stmt, bodycode. slotnames, i), 2 : length (stmt. args))
172
- if hasself && isa (a, Symbol)
173
- f = getfield (mod, stmt. args[1 ])
174
- mths = methods (f)
175
- if length (mths) == 1
176
- mth = first (mths)
177
- lnn = LineNumberNode (Int (mth. line), mth. file)
167
+ if lnn === nothing
168
+ bodycode = stmt3. args[end ]
169
+ if ! isa (bodycode, CodeInfo)
170
+ bodycode = @lookup (frame, bodycode)
171
+ end
172
+ if isa (bodycode, CodeInfo)
173
+ lnn = bodycode. linetable[1 ]
174
+ if lnn. line == 0 && lnn. file == :none
175
+ lnn = nothing
176
+ if length (bodycode. code) > 1
177
+ # This may be a kwarg method. Mimic LoweredCodeUtils.bodymethod,
178
+ # except without having a method
179
+ stmt = bodycode. code[end - 1 ]
180
+ if isa (stmt, Expr) && length (stmt. args) > 1
181
+ a = stmt. args[1 ]
182
+ hasself = any (i-> LoweredCodeUtils. is_self_call (stmt, bodycode. slotnames, i), 2 : length (stmt. args))
183
+ if isa (a, Core. SlotNumber)
184
+ a = bodycode. slotnames[a. id]
185
+ end
186
+ if hasself && (isa (a, Symbol) || isa (a, GlobalRef))
187
+ thismod, thisname = isa (a, Symbol) ? (mod, a) : (a. mod, a. name)
188
+ if isdefined (thismod, thisname)
189
+ f = getfield (thismod, thisname)
190
+ mths = methods (f)
191
+ if length (mths) == 1
192
+ mth = first (mths)
193
+ lnn = LineNumberNode (Int (mth. line), mth. file)
194
+ end
195
+ end
196
+ end
178
197
end
179
198
end
180
- else
181
- # Just try to find *any* line number
182
- for lnntmp in bodycode. linetable
183
- if lnntmp. line != 0 || lnntmp. file != :none
184
- lnn = lnntmp
185
- break
199
+ if lnn === nothing
200
+ # Just try to find *any* line number
201
+ for lnntmp in bodycode. linetable
202
+ if lnntmp. line != 0 || lnntmp. file != :none
203
+ lnn = lnntmp
204
+ break
205
+ end
186
206
end
187
207
end
188
208
end
209
+ elseif isexpr (bodycode, :lambda )
210
+ lnntmp = bodycode. args[end ][1 ]
211
+ if lnntmp. line != 0 || lnntmp. file != :none
212
+ lnn = lnntmp
213
+ end
189
214
end
190
- for sig in signatures
191
- add_signature! (methodinfo, sig, lnn)
215
+ end
216
+ if lnn === nothing
217
+ i = frame. framecode. src. codelocs[pc3]
218
+ while i > 0
219
+ lnntmp = frame. framecode. src. linetable[i]
220
+ if lnntmp. line != 0 || lnntmp. file != :none
221
+ lnn = lnntmp
222
+ break
223
+ end
224
+ i -= 1
192
225
end
193
- elseif isexpr (bodycode, :lambda )
194
- lnn = bodycode . args[ end ][ 1 ]
226
+ end
227
+ if lnn != = nothing && ( lnn. line != 0 || lnn . file != :none )
195
228
for sig in signatures
196
229
add_signature! (methodinfo, sig, lnn)
197
230
end
198
- else
199
- error (" unhandled bodycode " , bodycode)
200
231
end
201
232
end
202
233
elseif stmt. head == :(= ) && isa (stmt. args[1 ], Symbol)
0 commit comments