Skip to content

Commit 9118ea7

Browse files
authored
Fix partially_inline for unreachable (#56787)
1 parent 48be7ca commit 9118ea7

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

base/meta.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,10 +363,15 @@ function _partially_inline!(@nospecialize(x), slot_replacements::Vector{Any},
363363
return x
364364
end
365365
if isa(x, Core.ReturnNode)
366+
# Unreachable doesn't have val defined
367+
if !isdefined(x, :val)
368+
return x
369+
else
366370
return Core.ReturnNode(
367371
_partially_inline!(x.val, slot_replacements, type_signature, static_param_values,
368372
slot_offset, statement_offset, boundscheck),
369373
)
374+
end
370375
end
371376
if isa(x, Core.GotoIfNot)
372377
return Core.GotoIfNot(

test/meta.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,11 @@ ci = code_lowered(g, Tuple{Val{true}})[1]
276276
@test Meta.partially_inline!(copy(ci.code), Any[isdefined_globalref, 1], Tuple{typeof(isdefined_globalref), Int},
277277
[], 0, 0, :propagate)[1] == Expr(:isdefined, GlobalRef(Base, :foo))
278278

279+
withunreachable(s::String) = sin(s)
280+
ci = code_lowered(withunreachable, Tuple{String})[1]
281+
ci.code[end] = Core.ReturnNode()
282+
@test Meta.partially_inline!(copy(ci.code), Any[withunreachable, "foo"], Tuple{typeof(withunreachable), String},
283+
[], 0, 0, :propagate)[end] == Core.ReturnNode()
279284
end
280285

281286
@testset "Base.Meta docstrings" begin

0 commit comments

Comments
 (0)