Skip to content

Commit e2208bd

Browse files
JeffBezansonsimeonschaub
authored andcommitted
in inference, disallow 3-element Unions if one elt is abstract (JuliaLang#36200)
1 parent c12e5bd commit e2208bd

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

base/compiler/typelimits.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,11 @@ function type_more_complex(@nospecialize(t), @nospecialize(c), sources::SimpleVe
268268
return true
269269
end
270270

271+
union_count_abstract(x::Union) = union_count_abstract(x.a) + union_count_abstract(x.b)
272+
union_count_abstract(@nospecialize(x)) = !isdispatchelem(x)
273+
271274
function issimpleenoughtype(@nospecialize t)
272-
return unionlen(t) <= MAX_TYPEUNION_LENGTH && unioncomplexity(t) <= MAX_TYPEUNION_COMPLEXITY
275+
return unionlen(t)+union_count_abstract(t) <= MAX_TYPEUNION_LENGTH && unioncomplexity(t) <= MAX_TYPEUNION_COMPLEXITY
273276
end
274277

275278
# pick a wider type that contains both typea and typeb,

test/compiler/inference.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,10 @@ tmerge_test(Tuple{ComplexF64, ComplexF64, ComplexF32}, Tuple{Vararg{Union{Comple
9191
Tuple{Vararg{Complex}}, false)
9292
tmerge_test(Tuple{}, Tuple{Complex, Vararg{Union{ComplexF32, ComplexF64}}},
9393
Tuple{Vararg{Complex}})
94-
@test Core.Compiler.tmerge(Tuple{}, Union{Int16, Nothing, Tuple{ComplexF32, ComplexF32}}) ==
95-
Union{Int16, Nothing, Tuple{Vararg{ComplexF32}}}
96-
@test Core.Compiler.tmerge(Union{Int32, Nothing, Tuple{ComplexF32}}, Union{Int32, Nothing, Tuple{ComplexF32, ComplexF32}}) ==
97-
Union{Int32, Nothing, Tuple{Vararg{ComplexF32}}}
94+
@test Core.Compiler.tmerge(Tuple{}, Union{Nothing, Tuple{ComplexF32, ComplexF32}}) ==
95+
Union{Nothing, Tuple{Vararg{ComplexF32}}}
96+
@test Core.Compiler.tmerge(Union{Nothing, Tuple{ComplexF32}}, Union{Nothing, Tuple{ComplexF32, ComplexF32}}) ==
97+
Union{Nothing, Tuple{Vararg{ComplexF32}}}
9898

9999
# issue 9770
100100
@noinline x9770() = false

0 commit comments

Comments
 (0)