From be8fd2c874114ddf549714f0da3fb180626122f7 Mon Sep 17 00:00:00 2001 From: Oscar Dowson Date: Tue, 11 May 2021 21:09:50 +1200 Subject: [PATCH] Fix inference of max_values(::Union) (#40785) --- base/abstractset.jl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/base/abstractset.jl b/base/abstractset.jl index 697a1ca275aaec..442bbcb4bff48c 100644 --- a/base/abstractset.jl +++ b/base/abstractset.jl @@ -83,7 +83,11 @@ end max_values(::Type) = typemax(Int) max_values(T::Union{map(X -> Type{X}, BitIntegerSmall_types)...}) = 1 << (8*sizeof(T)) # saturated addition to prevent overflow with typemax(Int) -max_values(T::Union) = max(max_values(T.a), max_values(T.b), max_values(T.a) + max_values(T.b)) +function max_values(T::Union) + a = max_values(T.a)::Int + b = max_values(T.b)::Int + return max(a, b, a + b) +end max_values(::Type{Bool}) = 2 max_values(::Type{Nothing}) = 1