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
  • Loading branch information
aviatesk authored Oct 21, 2024
1 parent 1ba035d commit 08d11d0
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 @@ -601,8 +601,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 @@ -6055,3 +6055,11 @@ f55916(::Vararg{T,T}) where {T} = "2"
g55916(x) = f55916(x)
# this shouldn't error
@test only(code_typed(g55916, (Any,); optimize=false))[2] == 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 08d11d0

Please sign in to comment.