Skip to content

Commit d48243f

Browse files
aviateskKristofferC
authored andcommitted
inference: fix inference error from constructing invalid TypeVar (#56264)
- fixes #56248 (cherry picked from commit 08d11d0)
1 parent 0cf1432 commit d48243f

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

base/compiler/tfuncs.jl

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -574,8 +574,16 @@ add_tfunc(svec, 0, INT_INF, @nospecs((𝕃::AbstractLattice, args...)->SimpleVec
574574
return TypeVar
575575
end
576576
end
577-
tv = TypeVar(nval, lb, ub)
578-
return PartialTypeVar(tv, lb_certain, ub_certain)
577+
lb_valid = lb isa Type || lb isa TypeVar
578+
ub_valid = ub isa Type || ub isa TypeVar
579+
if lb_valid && ub_valid
580+
tv = TypeVar(nval, lb, ub)
581+
return PartialTypeVar(tv, lb_certain, ub_certain)
582+
elseif !lb_valid && lb_certain
583+
return Union{}
584+
elseif !ub_valid && ub_certain
585+
return Union{}
586+
end
579587
end
580588
return TypeVar
581589
end

test/compiler/inference.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5164,3 +5164,11 @@ end
51645164

51655165
issue55882_nfields(x::Union{T,Nothing}) where T<:Number = nfields(x)
51665166
@test only(Base.return_types(issue55882_nfields)) <: Int
5167+
5168+
# JuliaLang/julia#56248
5169+
@test only(Base.infer_return_type() do
5170+
TypeVar(:Issue56248, 1)
5171+
end) === Union{}
5172+
@test only(Base.infer_return_type() do
5173+
TypeVar(:Issue56248, Any, 1)
5174+
end) === Union{}

0 commit comments

Comments
 (0)