Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tfuncs: Be more robust in the face of uninhabited types #37945

Merged
merged 1 commit into from
Oct 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions base/compiler/tfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,7 @@ function getfield_tfunc(@nospecialize(s00), @nospecialize(name))
if isType(s) || !isa(s, DataType) || s.abstract
return Any
end
s = s::DataType
if s <: Tuple && name ⊑ Symbol
return Bottom
end
Expand All @@ -831,6 +832,9 @@ function getfield_tfunc(@nospecialize(s00), @nospecialize(name))
end
return Any
end
# If no value has this type, then this statement should be unreachable.
# Bail quickly now.
s.has_concrete_subtype || return Union{}
if s.name === _NAMEDTUPLE_NAME && !isconcretetype(s)
if isa(name, Const) && isa(name.val, Symbol)
if isa(s.parameters[1], Tuple)
Expand Down
3 changes: 3 additions & 0 deletions src/jltypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -1558,6 +1558,9 @@ static jl_svec_t *inst_ftypes(jl_svec_t *p, jl_typeenv_t *env, jl_typestack_t *s
jl_value_t *pi = jl_svecref(p, i);
JL_TRY {
pi = inst_type_w_(pi, env, stack, 1);
if (!jl_is_type(pi) && !jl_is_typevar(pi)) {
pi = jl_bottom_type;
}
}
JL_CATCH {
pi = jl_bottom_type;
Expand Down
7 changes: 7 additions & 0 deletions test/compiler/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2910,3 +2910,10 @@ end

# issue #37638
@test !(Core.Compiler.return_type(() -> (nothing, Any[]...)[2], Tuple{}) <: Vararg)

# Issue #37943
f37943(x::Any, i::Int) = getfield((x::Pair{false, Int}), i)
g37943(i::Int) = fieldtype(Pair{false, T} where T, i)
@test only(Base.return_types(f37943, Tuple{Any, Int})) === Union{}
@test only(Base.return_types(g37943, Tuple{Int})) === Union{Type{Union{}}, Type{Any}}