Skip to content

Commit 7a9c684

Browse files
aviateskKristofferC
authored andcommitted
inference: fix exct modeling of setglobal! (#57896)
(cherry picked from commit 626d541)
1 parent 318028a commit 7a9c684

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

Compiler/src/abstractinterpretation.jl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2561,7 +2561,6 @@ function abstract_eval_setglobalonce!(interp::AbstractInterpreter, sv::AbsIntSta
25612561
end
25622562
end
25632563

2564-
25652564
function abstract_eval_replaceglobal!(interp::AbstractInterpreter, sv::AbsIntState, saw_latestworld::Bool, argtypes::Vector{Any})
25662565
if length(argtypes) in (5, 6, 7)
25672566
(M, s, x, v) = argtypes[2], argtypes[3], argtypes[4], argtypes[5]
@@ -3624,7 +3623,7 @@ end
36243623

36253624
function global_assignment_rt_exct(interp::AbstractInterpreter, sv::AbsIntState, saw_latestworld::Bool, g::GlobalRef, @nospecialize(newty))
36263625
if saw_latestworld
3627-
return Pair{Any,Any}(newty, Union{ErrorException, TypeError})
3626+
return Pair{Any,Any}(newty, ErrorException)
36283627
end
36293628
(valid_worlds, ret) = scan_partitions((interp, _, partition)->global_assignment_binding_rt_exct(interp, partition, newty), interp, g, sv.world)
36303629
update_valid_age!(sv, valid_worlds)
@@ -3641,10 +3640,10 @@ function global_assignment_binding_rt_exct(interp::AbstractInterpreter, partitio
36413640
ty = kind == PARTITION_KIND_DECLARED ? Any : partition_restriction(partition)
36423641
wnewty = widenconst(newty)
36433642
if !hasintersect(wnewty, ty)
3644-
return Pair{Any,Any}(Bottom, TypeError)
3643+
return Pair{Any,Any}(Bottom, ErrorException)
36453644
elseif !(wnewty <: ty)
36463645
retty = tmeet(typeinf_lattice(interp), newty, ty)
3647-
return Pair{Any,Any}(retty, TypeError)
3646+
return Pair{Any,Any}(retty, ErrorException)
36483647
end
36493648
return Pair{Any,Any}(newty, Bottom)
36503649
end

Compiler/test/inference.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6194,3 +6194,8 @@ f57292(xs::Union{Tuple{String}, Int}...) = getfield(xs...)
61946194
g57292(xs::String...) = getfield(("abc",), 1, :not_atomic, xs...)
61956195
@test Base.infer_return_type(f57292) == String
61966196
@test Base.infer_return_type(g57292) == String
6197+
6198+
global invalid_setglobal!_exct_modeling::Int
6199+
@test Base.infer_exception_type((Float64,)) do x
6200+
setglobal!(@__MODULE__, :invalid_setglobal!_exct_modeling, x)
6201+
end == ErrorException

0 commit comments

Comments
 (0)