Skip to content

Commit 08d11d0

Browse files
authored
inference: fix inference error from constructing invalid TypeVar (JuliaLang#56264)
- fixes JuliaLang#56248
1 parent 1ba035d commit 08d11d0

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

base/compiler/tfuncs.jl

+10-2
Original file line numberDiff line numberDiff line change
@@ -601,8 +601,16 @@ add_tfunc(svec, 0, INT_INF, @nospecs((𝕃::AbstractLattice, args...)->SimpleVec
601601
return TypeVar
602602
end
603603
end
604-
tv = TypeVar(nval, lb, ub)
605-
return PartialTypeVar(tv, lb_certain, ub_certain)
604+
lb_valid = lb isa Type || lb isa TypeVar
605+
ub_valid = ub isa Type || ub isa TypeVar
606+
if lb_valid && ub_valid
607+
tv = TypeVar(nval, lb, ub)
608+
return PartialTypeVar(tv, lb_certain, ub_certain)
609+
elseif !lb_valid && lb_certain
610+
return Union{}
611+
elseif !ub_valid && ub_certain
612+
return Union{}
613+
end
606614
end
607615
return TypeVar
608616
end

test/compiler/inference.jl

+8
Original file line numberDiff line numberDiff line change
@@ -6055,3 +6055,11 @@ f55916(::Vararg{T,T}) where {T} = "2"
60556055
g55916(x) = f55916(x)
60566056
# this shouldn't error
60576057
@test only(code_typed(g55916, (Any,); optimize=false))[2] == Int
6058+
6059+
# JuliaLang/julia#56248
6060+
@test Base.infer_return_type() do
6061+
TypeVar(:Issue56248, 1)
6062+
end === Union{}
6063+
@test Base.infer_return_type() do
6064+
TypeVar(:Issue56248, Any, 1)
6065+
end === Union{}

0 commit comments

Comments
 (0)