@@ -1313,12 +1313,17 @@ static jl_value_t *intersect_all(jl_value_t *x, jl_value_t *y, jl_stenv_t *e);
13131313// intersect in nested union environment, similar to subtype_ccheck
13141314static jl_value_t * intersect_aside (jl_value_t * x , jl_value_t * y , jl_stenv_t * e , int depth )
13151315{
1316- jl_value_t * res ;
1316+ // band-aid for #30335
1317+ if (x == (jl_value_t * )jl_any_type && !jl_is_typevar (y ))
1318+ return y ;
1319+ if (y == (jl_value_t * )jl_any_type && !jl_is_typevar (x ))
1320+ return x ;
1321+
13171322 int savedepth = e -> invdepth ;
13181323 jl_unionstate_t oldRunions = e -> Runions ;
13191324 e -> invdepth = depth ;
13201325
1321- res = intersect_all (x , y , e );
1326+ jl_value_t * res = intersect_all (x , y , e );
13221327
13231328 e -> Runions = oldRunions ;
13241329 e -> invdepth = savedepth ;
@@ -1446,6 +1451,8 @@ static jl_value_t *intersect_var(jl_tvar_t *b, jl_value_t *a, jl_stenv_t *e, int
14461451 return (jl_value_t * )b ;
14471452 }
14481453 else if (bb -> constraintkind == 2 ) {
1454+ // TODO: removing this case fixes many test_brokens in test/subtype.jl
1455+ // but breaks other tests.
14491456 if (!subtype_in_env (a , bb -> ub , e ))
14501457 return jl_bottom_type ;
14511458 jl_value_t * lb = simple_join (bb -> lb , a );
@@ -1604,6 +1611,10 @@ static jl_value_t *finish_unionall(jl_value_t *res JL_MAYBE_UNROOTED, jl_varbind
16041611 // you can construct `T{x} where x` even if T's parameter is actually
16051612 // limited. in that case we might get an invalid instantiation here.
16061613 res = jl_substitute_var (res , vb -> var , varval );
1614+ // simplify chains of UnionAlls where bounds become equal
1615+ while (jl_is_unionall (res ) && obviously_egal (((jl_unionall_t * )res )-> var -> lb ,
1616+ ((jl_unionall_t * )res )-> var -> ub ))
1617+ res = jl_instantiate_unionall ((jl_unionall_t * )res , ((jl_unionall_t * )res )-> var -> lb );
16071618 }
16081619 JL_CATCH {
16091620 res = jl_bottom_type ;
0 commit comments