@@ -1301,6 +1301,8 @@ static int subtype_tuple(jl_datatype_t *xd, jl_datatype_t *yd, jl_stenv_t *e, in
13011301 return ans ;
13021302}
13031303
1304+ static int try_subtype_by_bounds (jl_value_t * a , jl_value_t * b , jl_stenv_t * e );
1305+
13041306// `param` means we are currently looking at a parameter of a type constructor
13051307// (as opposed to being outside any type constructor, or comparing variable bounds).
13061308// this is used to record the positions where type variables occur for the
@@ -1351,7 +1353,8 @@ static int subtype(jl_value_t *x, jl_value_t *y, jl_stenv_t *e, int param)
13511353 if (yy ) record_var_occurrence (yy , e , param );
13521354 if (yr ) {
13531355 record_var_occurrence (xx , e , param );
1354- return subtype (xx -> lb , yy -> ub , e , 0 );
1356+ int trysub = e -> intersection ? try_subtype_by_bounds (xx -> lb , yy -> ub , e ) : 0 ;
1357+ return trysub || subtype (xx -> lb , yy -> ub , e , 0 );
13551358 }
13561359 return var_lt ((jl_tvar_t * )x , y , e , param );
13571360 }
@@ -2483,7 +2486,7 @@ static jl_value_t *bound_var_below(jl_tvar_t *tv, jl_varbinding_t *bb, jl_stenv_
24832486
24842487static int subtype_by_bounds (jl_value_t * x , jl_value_t * y , jl_stenv_t * e ) JL_NOTSAFEPOINT ;
24852488
2486- // similar to `subtype_by_bounds`, used to avoid stack-overflow caused by circulation constraints.
2489+ // similar to `subtype_by_bounds`, used to avoid stack-overflow caused by circular constraints.
24872490static int try_subtype_by_bounds (jl_value_t * a , jl_value_t * b , jl_stenv_t * e )
24882491{
24892492 if (jl_is_uniontype (a ))
@@ -2492,22 +2495,21 @@ static int try_subtype_by_bounds(jl_value_t *a, jl_value_t *b, jl_stenv_t *e)
24922495 else if (jl_is_uniontype (b ))
24932496 return try_subtype_by_bounds (a , ((jl_uniontype_t * )b )-> a , e ) ||
24942497 try_subtype_by_bounds (a , ((jl_uniontype_t * )b )-> b , e );
2495- else if (jl_egal (a , b ))
2498+ else if (a == jl_bottom_type || b == ( jl_value_t * ) jl_any_type || obviously_egal (a , b ))
24962499 return 1 ;
24972500 else if (!jl_is_typevar (b ))
24982501 return 0 ;
2499- jl_varbinding_t * vb = e -> vars ;
2500- while (vb != NULL ) {
2501- if (subtype_by_bounds (b , (jl_value_t * )vb -> var , e ) && obviously_in_union (a , vb -> ub ))
2502- return 1 ;
2503- vb = vb -> prev ;
2504- }
2505- return 0 ;
2502+ else if (jl_is_typevar (a ) && subtype_by_bounds (a , b , e ))
2503+ return 1 ;
2504+ // check if `Union{a, ...} <: b`.
2505+ jl_varbinding_t * vb = lookup (e , (jl_tvar_t * )b );
2506+ jl_value_t * blb = vb ? vb -> lb : ((jl_tvar_t * )b )-> lb ;
2507+ return obviously_in_union (a , blb );
25062508}
25072509
25082510static int try_subtype_in_env (jl_value_t * a , jl_value_t * b , jl_stenv_t * e )
25092511{
2510- if (a == jl_bottom_type || b == ( jl_value_t * ) jl_any_type || try_subtype_by_bounds (a , b , e ))
2512+ if (try_subtype_by_bounds (a , b , e ))
25112513 return 1 ;
25122514 jl_savedenv_t se ;
25132515 save_env (e , & se , 1 );
0 commit comments