Skip to content

Commit

Permalink
inference: fix inference error from constructing invalid TypeVar (#…
Browse files Browse the repository at this point in the history
…56264)

- fixes #56248

(cherry picked from commit 08d11d0)
  • Loading branch information
aviatesk authored and KristofferC committed Jan 2, 2025
1 parent 35ffb65 commit 3dd91a1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
12 changes: 10 additions & 2 deletions base/compiler/tfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -587,8 +587,16 @@ add_tfunc(svec, 0, INT_INF, @nospecs((𝕃::AbstractLattice, args...)->SimpleVec
return TypeVar
end
end
tv = TypeVar(nval, lb, ub)
return PartialTypeVar(tv, lb_certain, ub_certain)
lb_valid = lb isa Type || lb isa TypeVar
ub_valid = ub isa Type || ub isa TypeVar
if lb_valid && ub_valid
tv = TypeVar(nval, lb, ub)
return PartialTypeVar(tv, lb_certain, ub_certain)
elseif !lb_valid && lb_certain
return Union{}
elseif !ub_valid && ub_certain
return Union{}
end
end
return TypeVar
end
Expand Down
8 changes: 8 additions & 0 deletions test/compiler/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5685,3 +5685,11 @@ t255751 = Array{Float32, 3}

issue55882_nfields(x::Union{T,Nothing}) where T<:Number = nfields(x)
@test Base.infer_return_type(issue55882_nfields) <: Int

# JuliaLang/julia#56248
@test Base.infer_return_type() do
TypeVar(:Issue56248, 1)
end === Union{}
@test Base.infer_return_type() do
TypeVar(:Issue56248, Any, 1)
end === Union{}

0 comments on commit 3dd91a1

Please sign in to comment.