diff --git a/base/compiler/typelimits.jl b/base/compiler/typelimits.jl index 2c8d7a58055734..88948421f1c017 100644 --- a/base/compiler/typelimits.jl +++ b/base/compiler/typelimits.jl @@ -268,8 +268,11 @@ function type_more_complex(@nospecialize(t), @nospecialize(c), sources::SimpleVe return true end +union_count_abstract(x::Union) = union_count_abstract(x.a) + union_count_abstract(x.b) +union_count_abstract(@nospecialize(x)) = !isdispatchelem(x) + function issimpleenoughtype(@nospecialize t) - return unionlen(t) <= MAX_TYPEUNION_LENGTH && unioncomplexity(t) <= MAX_TYPEUNION_COMPLEXITY + return unionlen(t)+union_count_abstract(t) <= MAX_TYPEUNION_LENGTH && unioncomplexity(t) <= MAX_TYPEUNION_COMPLEXITY end # pick a wider type that contains both typea and typeb, diff --git a/test/compiler/inference.jl b/test/compiler/inference.jl index 7092b8fc38e972..f1ddc7349c8439 100644 --- a/test/compiler/inference.jl +++ b/test/compiler/inference.jl @@ -91,10 +91,10 @@ tmerge_test(Tuple{ComplexF64, ComplexF64, ComplexF32}, Tuple{Vararg{Union{Comple Tuple{Vararg{Complex}}, false) tmerge_test(Tuple{}, Tuple{Complex, Vararg{Union{ComplexF32, ComplexF64}}}, Tuple{Vararg{Complex}}) -@test Core.Compiler.tmerge(Tuple{}, Union{Int16, Nothing, Tuple{ComplexF32, ComplexF32}}) == - Union{Int16, Nothing, Tuple{Vararg{ComplexF32}}} -@test Core.Compiler.tmerge(Union{Int32, Nothing, Tuple{ComplexF32}}, Union{Int32, Nothing, Tuple{ComplexF32, ComplexF32}}) == - Union{Int32, Nothing, Tuple{Vararg{ComplexF32}}} +@test Core.Compiler.tmerge(Tuple{}, Union{Nothing, Tuple{ComplexF32, ComplexF32}}) == + Union{Nothing, Tuple{Vararg{ComplexF32}}} +@test Core.Compiler.tmerge(Union{Nothing, Tuple{ComplexF32}}, Union{Nothing, Tuple{ComplexF32, ComplexF32}}) == + Union{Nothing, Tuple{Vararg{ComplexF32}}} # issue 9770 @noinline x9770() = false