@@ -957,8 +957,8 @@ function fieldtype_tfunc(@nospecialize(s0), @nospecialize(name))
957
957
end
958
958
if s0 === Any || s0 === Type || DataType ⊑ s0 || UnionAll ⊑ s0
959
959
# For a generic DataType, one of the fields could still be a TypeVar
960
- # which is not a Type
961
- return Union{Type, TypeVar}
960
+ # which is not a Type. Tuple{...} can also contain Symbols etc.
961
+ return Any
962
962
end
963
963
# fieldtype only accepts Types
964
964
if isa (s0, Const) && ! (isa (s0. val, DataType) || isa (s0. val, UnionAll) || isa (s0. val, Union))
@@ -986,14 +986,14 @@ function _fieldtype_tfunc(@nospecialize(s), exact::Bool, @nospecialize(name))
986
986
return tmerge (_fieldtype_tfunc (rewrap (u. a, s), exact, name),
987
987
_fieldtype_tfunc (rewrap (u. b, s), exact, name))
988
988
end
989
- u isa DataType || return Union{Type, TypeVar}
989
+ u isa DataType || return Any
990
990
if u. abstract
991
991
# Abstract types have no fields
992
992
exact && return Bottom
993
993
# Type{...} without free typevars has no subtypes, so it is actually
994
994
# exact, even if `exact` is false.
995
995
isType (u) && ! has_free_typevars (u. parameters[1 ]) && return Bottom
996
- return Union{Type, TypeVar}
996
+ return Any
997
997
end
998
998
if u. name === _NAMEDTUPLE_NAME && ! isconcretetype (u)
999
999
# TODO : better approximate inference
@@ -1020,8 +1020,15 @@ function _fieldtype_tfunc(@nospecialize(s), exact::Bool, @nospecialize(name))
1020
1020
else
1021
1021
ft1 = Type{ft1}
1022
1022
end
1023
+ elseif ft1 isa Type || ft1 isa TypeVar
1024
+ if ft1 === Any && u. name === Tuple. name
1025
+ # Tuple{:x}
1026
+ ft1 = Any
1027
+ else
1028
+ ft1 = Type{ft} where ft<: ft1
1029
+ end
1023
1030
else
1024
- ft1 = Type{ft} where ft <: ft1
1031
+ ft1 = Const ( ft1)
1025
1032
end
1026
1033
t = tmerge (t, ft1)
1027
1034
t === Any && break
@@ -1044,6 +1051,9 @@ function _fieldtype_tfunc(@nospecialize(s), exact::Bool, @nospecialize(name))
1044
1051
else
1045
1052
ft = ftypes[fld]
1046
1053
end
1054
+ if ! isa (ft, Type) && ! isa (ft, TypeVar)
1055
+ return Const (ft)
1056
+ end
1047
1057
1048
1058
exactft = exact || (! has_free_typevars (ft) && u. name != = Tuple. name)
1049
1059
ft = rewrap_unionall (ft, s)
@@ -1053,6 +1063,10 @@ function _fieldtype_tfunc(@nospecialize(s), exact::Bool, @nospecialize(name))
1053
1063
end
1054
1064
return Type{ft}
1055
1065
end
1066
+ if u. name === Tuple. name && ft === Any
1067
+ # Tuple{:x} is possible
1068
+ return Any
1069
+ end
1056
1070
return Type{<: ft }
1057
1071
end
1058
1072
add_tfunc (fieldtype, 2 , 3 , fieldtype_tfunc, 0 )
0 commit comments