From 5b1d1ba14fe318ebe3927c25122153c00914149b Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Mon, 23 Aug 2021 16:48:37 -0400 Subject: [PATCH 1/2] fix #41908, inference error in subst_trivial_bounds --- base/compiler/utilities.jl | 10 +++++++++- test/compiler/inference.jl | 7 +++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/base/compiler/utilities.jl b/base/compiler/utilities.jl index 5d4d52172a300..ed09d5316473a 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 1e61cc9e44094..302889b7dcc53 100644 --- a/test/compiler/inference.jl +++ b/test/compiler/inference.jl @@ -3403,3 +3403,10 @@ end @test @inferred(f40177(T)) == fieldtype(T, 1) end end + +# issue #41908 +struct Diagonalish{T,V<:AbstractVector{T}} <: AbstractMatrix{T} +end +f41908(x::Diagonalish{Int, T}) where {Int<:T<:Int} = 1 +g41908() = f41908(Any[1][1]) +@test Base.return_types(g41908, ()) == Any[Int] From ee53aca50b71b8644bc728d1c8f96428260d32c8 Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Tue, 24 Aug 2021 13:32:19 -0400 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: Martin Holters --- test/compiler/inference.jl | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/test/compiler/inference.jl b/test/compiler/inference.jl index 302889b7dcc53..4ce4eca03b91e 100644 --- a/test/compiler/inference.jl +++ b/test/compiler/inference.jl @@ -3405,8 +3405,6 @@ end end # issue #41908 -struct Diagonalish{T,V<:AbstractVector{T}} <: AbstractMatrix{T} -end -f41908(x::Diagonalish{Int, T}) where {Int<:T<:Int} = 1 +f41908(x::Complex{T}) where {String<:T<:String} = 1 g41908() = f41908(Any[1][1]) -@test Base.return_types(g41908, ()) == Any[Int] +@test only(Base.return_types(g41908, ())) <: Int