Skip to content

Commit 382ba35

Browse files
authored
Support convert(LineNumberNode, ::LineInfoNode) (#50676)
xref timholy/CodeTracking.jl#113. It looks like that method might not even be important anymore for CodeTracking and the Revise stack, but because we have lots of packages that dive into internals, having this seems to make sense.
1 parent 441fcb1 commit 382ba35

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

base/expr.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ macro gensym(names...)
3333
return blk
3434
end
3535

36+
## line numbers ##
37+
convert(::Type{LineNumberNode}, lin::Core.LineInfoNode) = LineNumberNode(Int(lin.line), lin.file)
38+
3639
## expressions ##
3740

3841
isexpr(@nospecialize(ex), head::Symbol) = isa(ex, Expr) && ex.head === head

test/core.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8044,3 +8044,7 @@ end
80448044
# `SimpleVector`-operations should be concrete-eval eligible
80458045
@test Core.Compiler.is_foldable(Base.infer_effects(length, (Core.SimpleVector,)))
80468046
@test Core.Compiler.is_foldable(Base.infer_effects(getindex, (Core.SimpleVector,Int)))
8047+
8048+
let lin = Core.LineInfoNode(Base, first(methods(convert)), :foo, Int32(5), Int32(0))
8049+
@test convert(LineNumberNode, lin) == LineNumberNode(5, :foo)
8050+
end

0 commit comments

Comments
 (0)