Skip to content

Commit 7f3d3ee

Browse files
authored
inference: fix exct modeling of setglobal! (JuliaLang#57896)
1 parent 2e127d0 commit 7f3d3ee

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/abstractinterpretation.jl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2565,7 +2565,6 @@ function abstract_eval_setglobalonce!(interp::AbstractInterpreter, sv::AbsIntSta
25652565
end
25662566
end
25672567

2568-
25692568
function abstract_eval_replaceglobal!(interp::AbstractInterpreter, sv::AbsIntState, saw_latestworld::Bool, argtypes::Vector{Any})
25702569
if length(argtypes) in (5, 6, 7)
25712570
(M, s, x, v) = argtypes[2], argtypes[3], argtypes[4], argtypes[5]
@@ -3671,7 +3670,7 @@ end
36713670

36723671
function global_assignment_rt_exct(interp::AbstractInterpreter, sv::AbsIntState, saw_latestworld::Bool, g::GlobalRef, @nospecialize(newty))
36733672
if saw_latestworld
3674-
return Pair{Any,Any}(newty, Union{ErrorException, TypeError})
3673+
return Pair{Any,Any}(newty, ErrorException)
36753674
end
36763675
(valid_worlds, ret) = scan_partitions((interp, _, partition)->global_assignment_binding_rt_exct(interp, partition, newty), interp, g, sv.world)
36773676
update_valid_age!(sv, valid_worlds)
@@ -3688,10 +3687,10 @@ function global_assignment_binding_rt_exct(interp::AbstractInterpreter, partitio
36883687
ty = kind == PARTITION_KIND_DECLARED ? Any : partition_restriction(partition)
36893688
wnewty = widenconst(newty)
36903689
if !hasintersect(wnewty, ty)
3691-
return Pair{Any,Any}(Bottom, TypeError)
3690+
return Pair{Any,Any}(Bottom, ErrorException)
36923691
elseif !(wnewty <: ty)
36933692
retty = tmeet(typeinf_lattice(interp), newty, ty)
3694-
return Pair{Any,Any}(retty, TypeError)
3693+
return Pair{Any,Any}(retty, ErrorException)
36953694
end
36963695
return Pair{Any,Any}(newty, Bottom)
36973696
end

test/inference.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6408,4 +6408,9 @@ let src = code_typed1((Base.RefValue{String}, String)) do x, val
64086408
@test isa(retval, Core.SSAValue)
64096409
end
64106410

6411+
global invalid_setglobal!_exct_modeling::Int
6412+
@test Base.infer_exception_type((Float64,)) do x
6413+
setglobal!(@__MODULE__, :invalid_setglobal!_exct_modeling, x)
6414+
end == ErrorException
6415+
64116416
end # module inference

0 commit comments

Comments
 (0)