Skip to content

Commit 3778e1e

Browse files
JeffBezansonmartinholters
authored andcommitted
fix JuliaLang#41908, inference error in subst_trivial_bounds (JuliaLang#41976)
Co-authored-by: Martin Holters <martin.holters@hsu-hh.de>
1 parent b555e13 commit 3778e1e

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
@@ -156,7 +156,15 @@ function subst_trivial_bounds(@nospecialize(atypes))
156156
end
157157
v = atypes.var
158158
if isconcretetype(v.ub) || v.lb === v.ub
159-
return subst_trivial_bounds(atypes{v.ub})
159+
subst = try
160+
atypes{v.ub}
161+
catch
162+
# Note in rare cases a var bound might not be valid to substitute.
163+
nothing
164+
end
165+
if subst !== nothing
166+
return subst_trivial_bounds(subst)
167+
end
160168
end
161169
return UnionAll(v, subst_trivial_bounds(atypes.body))
162170
end

test/compiler/inference.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3408,3 +3408,8 @@ end
34083408
@test @inferred(f40177(T)) == fieldtype(T, 1)
34093409
end
34103410
end
3411+
3412+
# issue #41908
3413+
f41908(x::Complex{T}) where {String<:T<:String} = 1
3414+
g41908() = f41908(Any[1][1])
3415+
@test only(Base.return_types(g41908, ())) <: Int

0 commit comments

Comments
 (0)