Skip to content

Commit 230647c

Browse files
JeffBezansonmartinholters
authored andcommitted
fix #41908, inference error in subst_trivial_bounds (#41976)
Co-authored-by: Martin Holters <[email protected]> (cherry picked from commit e2aeefb)
1 parent c10d145 commit 230647c

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

base/compiler/utilities.jl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,15 @@ function subst_trivial_bounds(@nospecialize(atypes))
154154
end
155155
v = atypes.var
156156
if isconcretetype(v.ub) || v.lb === v.ub
157-
return subst_trivial_bounds(atypes{v.ub})
157+
subst = try
158+
atypes{v.ub}
159+
catch
160+
# Note in rare cases a var bound might not be valid to substitute.
161+
nothing
162+
end
163+
if subst !== nothing
164+
return subst_trivial_bounds(subst)
165+
end
158166
end
159167
return UnionAll(v, subst_trivial_bounds(atypes.body))
160168
end

test/compiler/inference.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3085,3 +3085,8 @@ end
30853085
end
30863086
return x
30873087
end) === Union{Int, Float64, Char}
3088+
3089+
# issue #41908
3090+
f41908(x::Complex{T}) where {String<:T<:String} = 1
3091+
g41908() = f41908(Any[1][1])
3092+
@test only(Base.return_types(g41908, ())) <: Int

0 commit comments

Comments
 (0)