@@ -3521,19 +3521,29 @@ mono_method_is_generic_sharable_full (MonoMethod *method, gboolean allow_type_va
35213521
35223522 if (method -> is_inflated ) {
35233523 MonoMethodInflated * inflated = (MonoMethodInflated * )method ;
3524- MonoGenericContext * context = & inflated -> context ;
3524+ MonoGenericContext * ctx = & inflated -> context ;
35253525
3526- if (!mono_generic_context_is_sharable_full (context , allow_type_vars , allow_partial ))
3526+ if (!mono_generic_context_is_sharable_full (ctx , allow_type_vars , allow_partial ))
35273527 return FALSE;
35283528
35293529 g_assert (inflated -> declaring );
35303530
3531- #if 0
3532- if (inflated -> declaring -> is_generic ) {
3533- if (has_constraints (mono_method_get_generic_container (inflated -> declaring ))) {
3531+ /*
3532+ * If all the parameters are primitive types and constraints prevent
3533+ * them from being instantiated with enums, then only the primitive
3534+ * type instantiation is possible, thus sharing is not useful.
3535+ * Happens with generic math interfaces.
3536+ */
3537+ if ((!ctx -> class_inst || is_primitive_inst (ctx -> class_inst )) &&
3538+ (!ctx -> method_inst || is_primitive_inst (ctx -> method_inst ))) {
3539+ MonoGenericContainer * container = mono_method_get_generic_container (inflated -> declaring );
3540+ if (container && has_constraints (container )) {
3541+ for (int i = 0 ; i < container -> type_argc ; ++ i ) {
3542+ if (!gparam_can_be_enum (& container -> type_params [i ]))
3543+ return FALSE;
3544+ }
35343545 }
35353546 }
3536- #endif
35373547 }
35383548
35393549 if (mono_class_is_ginst (method -> klass )) {
@@ -3544,12 +3554,6 @@ mono_method_is_generic_sharable_full (MonoMethod *method, gboolean allow_type_va
35443554 g_assert (mono_class_get_generic_class (method -> klass )-> container_class &&
35453555 mono_class_is_gtd (mono_class_get_generic_class (method -> klass )-> container_class ));
35463556
3547- /*
3548- * If all the parameters are primitive types and constraints prevent
3549- * them from being instantiated with enums, then only the primitive
3550- * type instantiation is possible, thus sharing is not useful.
3551- * Happens with generic math interfaces.
3552- */
35533557 if ((!ctx -> class_inst || is_primitive_inst (ctx -> class_inst )) &&
35543558 (!ctx -> method_inst || is_primitive_inst (ctx -> method_inst ))) {
35553559 MonoGenericContainer * container = mono_class_get_generic_container (mono_class_get_generic_class (method -> klass )-> container_class );
0 commit comments