Skip to content

Commit 3dd91a1

Browse files
aviateskKristofferC
authored andcommitted
inference: fix inference error from constructing invalid TypeVar (#56264)
- fixes #56248 (cherry picked from commit 08d11d0)
1 parent 35ffb65 commit 3dd91a1

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
@@ -587,8 +587,16 @@ add_tfunc(svec, 0, INT_INF, @nospecs((𝕃::AbstractLattice, args...)->SimpleVec
587587
return TypeVar
588588
end
589589
end
590-
tv = TypeVar(nval, lb, ub)
591-
return PartialTypeVar(tv, lb_certain, ub_certain)
590+
lb_valid = lb isa Type || lb isa TypeVar
591+
ub_valid = ub isa Type || ub isa TypeVar
592+
if lb_valid && ub_valid
593+
tv = TypeVar(nval, lb, ub)
594+
return PartialTypeVar(tv, lb_certain, ub_certain)
595+
elseif !lb_valid && lb_certain
596+
return Union{}
597+
elseif !ub_valid && ub_certain
598+
return Union{}
599+
end
592600
end
593601
return TypeVar
594602
end

test/compiler/inference.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5685,3 +5685,11 @@ t255751 = Array{Float32, 3}
56855685

56865686
issue55882_nfields(x::Union{T,Nothing}) where T<:Number = nfields(x)
56875687
@test Base.infer_return_type(issue55882_nfields) <: Int
5688+
5689+
# JuliaLang/julia#56248
5690+
@test Base.infer_return_type() do
5691+
TypeVar(:Issue56248, 1)
5692+
end === Union{}
5693+
@test Base.infer_return_type() do
5694+
TypeVar(:Issue56248, Any, 1)
5695+
end === Union{}

0 commit comments

Comments
 (0)