From 3778e1ea12028046b5cfef33dac72f767971ad72 Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Tue, 24 Aug 2021 22:27:10 -0400 Subject: [PATCH] fix #41908, inference error in subst_trivial_bounds (#41976) Co-authored-by: Martin Holters --- base/compiler/utilities.jl | 10 +++++++++- test/compiler/inference.jl | 5 +++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/base/compiler/utilities.jl b/base/compiler/utilities.jl index 5d4d52172a300a..ed09d5316473a4 100644 --- a/base/compiler/utilities.jl +++ b/base/compiler/utilities.jl @@ -156,7 +156,15 @@ function subst_trivial_bounds(@nospecialize(atypes)) end v = atypes.var if isconcretetype(v.ub) || v.lb === v.ub - return subst_trivial_bounds(atypes{v.ub}) + subst = try + atypes{v.ub} + catch + # Note in rare cases a var bound might not be valid to substitute. + nothing + end + if subst !== nothing + return subst_trivial_bounds(subst) + end end return UnionAll(v, subst_trivial_bounds(atypes.body)) end diff --git a/test/compiler/inference.jl b/test/compiler/inference.jl index a5f83160ee7e23..4890329f1a3751 100644 --- a/test/compiler/inference.jl +++ b/test/compiler/inference.jl @@ -3408,3 +3408,8 @@ end @test @inferred(f40177(T)) == fieldtype(T, 1) end end + +# issue #41908 +f41908(x::Complex{T}) where {String<:T<:String} = 1 +g41908() = f41908(Any[1][1]) +@test only(Base.return_types(g41908, ())) <: Int