@@ -660,21 +660,21 @@ function type_depth(t::ANY)
660
660
return 0
661
661
end
662
662
663
- function limit_type_depth (t:: ANY , d:: Int , cov:: Bool = true , var :: Union{Void, TypeVar}= nothing )
663
+ function limit_type_depth (t:: ANY , d:: Int , cov:: Bool = true , vars :: Vector{ TypeVar}= TypeVar[] )
664
664
if isa (t,Union)
665
665
if d > MAX_TYPE_DEPTH
666
666
return Any
667
667
end
668
- return Union{map (x-> limit_type_depth (x, d+ 1 , cov, var ), (t. a,t. b))... }
668
+ return Union{map (x-> limit_type_depth (x, d+ 1 , cov, vars ), (t. a,t. b))... }
669
669
elseif isa (t,UnionAll)
670
670
v = t. var
671
671
if v. ub === Any
672
672
if v. lb === Bottom
673
- return UnionAll (t. var, limit_type_depth (t. body, d, cov, var ))
673
+ return UnionAll (t. var, limit_type_depth (t. body, d, cov, vars ))
674
674
end
675
675
ub = Any
676
676
else
677
- ub = limit_type_depth (v. ub, d+ 1 , true , nothing )
677
+ ub = limit_type_depth (v. ub, d+ 1 , true )
678
678
end
679
679
if v. lb === Bottom || type_depth (v. lb) > MAX_TYPE_DEPTH
680
680
# note: lower bounds need to be widened by making them lower
@@ -683,25 +683,22 @@ function limit_type_depth(t::ANY, d::Int, cov::Bool=true, var::Union{Void,TypeVa
683
683
lb = v. lb
684
684
end
685
685
v2 = TypeVar (v. name, lb, ub)
686
- return UnionAll (v2, limit_type_depth (t{v2}, d, cov, var ))
686
+ return UnionAll (v2, limit_type_depth (t{v2}, d, cov, vars ))
687
687
elseif ! isa (t,DataType)
688
688
return t
689
689
end
690
690
P = t. parameters
691
691
isempty (P) && return t
692
692
if d > MAX_TYPE_DEPTH
693
693
cov && return t. name. wrapper
694
- # TODO mutating a TypeVar is not great style
695
- var . ub = t . name . wrapper
694
+ var = TypeVar ( gensym (), t . name . wrapper)
695
+ push! (vars, var)
696
696
return var
697
697
end
698
698
stillcov = cov && (t. name === Tuple. name)
699
- if cov && ! stillcov
700
- var = TypeVar (:_ )
701
- end
702
- Q = map (x-> limit_type_depth (x, d+ 1 , stillcov, var), P)
699
+ Q = map (x-> limit_type_depth (x, d+ 1 , stillcov, vars), P)
703
700
R = t. name. wrapper{Q... }
704
- return (cov && ! stillcov) ? UnionAll (var , R) : R
701
+ return (cov && ! stillcov) ? foldr (UnionAll , R, vars ) : R
705
702
end
706
703
707
704
const DataType_name_fieldindex = fieldindex (DataType, :name )
0 commit comments