Skip to content

Commit a9743d8

Browse files
authored
inference: fix precision regression (#37365)
While in 1d08d70 we wanted to avoid combining two types, we did not intend to prevent a type from being just a pass-through value.
1 parent b508f9d commit a9743d8

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

base/compiler/typelimits.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,8 @@ end
286286
# but without losing too much precision in common cases
287287
# and also trying to be mostly associative and commutative
288288
function tmerge(@nospecialize(typea), @nospecialize(typeb))
289+
typea === Union{} && return typeb
290+
typeb === Union{} && return typea
289291
suba = typea typeb
290292
suba && issimpleenoughtype(typeb) && return typeb
291293
subb = typeb typea

test/compiler/inference.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,14 @@ tmerge_test(Tuple{}, Tuple{Complex, Vararg{Union{ComplexF32, ComplexF64}}},
9999
@test Core.Compiler.tmerge(Union{Nothing, Tuple{ComplexF32}}, Union{Nothing, Tuple{ComplexF32, ComplexF32}}) ==
100100
Union{Nothing, Tuple{Vararg{ComplexF32}}}
101101
@test Core.Compiler.tmerge(Vector{Int}, Core.Compiler.tmerge(Vector{String}, Vector{Bool})) == Vector
102+
@test Core.Compiler.tmerge(Base.BitIntegerType, Union{}) === Base.BitIntegerType
103+
@test Core.Compiler.tmerge(Union{}, Base.BitIntegerType) === Base.BitIntegerType
104+
105+
struct SomethingBits
106+
x::Base.BitIntegerType
107+
end
108+
@test Base.return_types(getproperty, (SomethingBits, Symbol)) == Any[Base.BitIntegerType]
109+
102110

103111
# issue 9770
104112
@noinline x9770() = false

0 commit comments

Comments
 (0)