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 Oct 30, 2024
1 parent 0cf1432 commit b23811e
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 @@ -574,8 +574,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 @@ -5164,3 +5164,11 @@ end

issue55882_nfields(x::Union{T,Nothing}) where T<:Number = nfields(x)
@test only(Base.return_types(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 b23811e

Please sign in to comment.