Skip to content

Commit 9a20417

Browse files
authored
Compiler: fix tmerge(Const(s), Const(t)) st. (s !== t) && (s == t) (#56915)
Updates #56913
1 parent 638dacc commit 9a20417

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

Compiler/src/typelimits.jl

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ end
587587
@nospecializeinfer function tmerge_partial_struct(𝕃::PartialsLattice, @nospecialize(typea), @nospecialize(typeb))
588588
aty = widenconst(typea)
589589
bty = widenconst(typeb)
590-
if aty === bty
590+
if aty === bty && !isType(aty)
591591
if typea isa PartialStruct
592592
if typeb isa PartialStruct
593593
nflds = min(length(typea.fields), length(typeb.fields))
@@ -605,9 +605,6 @@ end
605605
for i = 1:nflds
606606
ai = getfield_tfunc(𝕃, typea, Const(i))
607607
bi = getfield_tfunc(𝕃, typeb, Const(i))
608-
# N.B.: We're assuming here that !isType(aty), because that case
609-
# only arises when typea === typeb, which should have been caught
610-
# before calling this.
611608
ft = fieldtype(aty, i)
612609
if is_lattice_equal(𝕃, ai, bi) || is_lattice_equal(𝕃, ai, ft)
613610
# Since ai===bi, the given type has no restrictions on complexity.

Compiler/test/inference.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2295,13 +2295,20 @@ let 𝕃ᵢ = InferenceLattice(MustAliasesLattice(BaseInferenceLattice.instance)
22952295
@test tmerge(MustAlias(2, AliasableField{Any}, 1, Int), Const(nothing)) === Union{Int,Nothing}
22962296
@test tmerge(Const(nothing), MustAlias(2, AliasableField{Any}, 1, Any)) === Any
22972297
@test tmerge(Const(nothing), MustAlias(2, AliasableField{Any}, 1, Int)) === Union{Int,Nothing}
2298+
tmerge(Const(AbstractVector{<:Any}), Const(AbstractVector{T} where {T})) # issue #56913
22982299
@test isa_tfunc(MustAlias(2, AliasableField{Any}, 1, Bool), Const(Bool)) === Const(true)
22992300
@test isa_tfunc(MustAlias(2, AliasableField{Any}, 1, Bool), Type{Bool}) === Const(true)
23002301
@test isa_tfunc(MustAlias(2, AliasableField{Any}, 1, Int), Type{Bool}) === Const(false)
23012302
@test ifelse_tfunc(MustAlias(2, AliasableField{Any}, 1, Bool), Int, Int) === Int
23022303
@test ifelse_tfunc(MustAlias(2, AliasableField{Any}, 1, Int), Int, Int) === Union{}
23032304
end
23042305

2306+
@testset "issue #56913: `BoundsError` in type inference" begin
2307+
R = UnitRange{Int}
2308+
@test Type{AbstractVector} == Base.infer_return_type(Base.promote_typeof, Tuple{R, R, Vector{Any}, Vararg{R}})
2309+
@test Type{AbstractVector} == Base.infer_return_type(Base.promote_typeof, Tuple{R, R, Vector{Any}, R, Vararg{R}})
2310+
end
2311+
23052312
maybeget_mustalias_tmerge(x::AliasableField) = x.f
23062313
maybeget_mustalias_tmerge(x) = x
23072314
@test Base.return_types((Union{Nothing,AliasableField{Any}},); interp=MustAliasInterpreter()) do x

0 commit comments

Comments
 (0)