[691531] Variance conversion requires type parameters to be reference types
[mono.git] / mcs / mcs / convert.cs
index 3283e58b35f917c4d67ebb861ff9eb19601ecad1..020c842755bf3d1c86cf09fa865cb1e7d15db426 100644 (file)
@@ -194,6 +194,11 @@ namespace Mono.CSharp {
                // Implicit reference conversions
                //
                public static bool ImplicitReferenceConversionExists (TypeSpec expr_type, TypeSpec target_type)
+               {
+                       return ImplicitReferenceConversionExists (expr_type, target_type, true);
+               }
+
+               static bool ImplicitReferenceConversionExists (TypeSpec expr_type, TypeSpec target_type, bool refOnlyTypeParameter)
                {
                        // It's here only to speed things up
                        if (target_type.IsStruct)
@@ -201,7 +206,8 @@ namespace Mono.CSharp {
 
                        switch (expr_type.Kind) {
                        case MemberKind.TypeParameter:
-                               return ImplicitTypeParameterConversion (null, (TypeParameterSpec) expr_type, target_type) != null;
+                               return ImplicitTypeParameterConversion (null, (TypeParameterSpec) expr_type, target_type) != null &&
+                                       (!refOnlyTypeParameter || TypeSpec.IsReferenceType (expr_type));
 
                        case MemberKind.Class:
                                //
@@ -698,7 +704,7 @@ namespace Mono.CSharp {
                        if (ImplicitNumericConversion (null, expr_type, target_type) != null)
                                return true;
 
-                       if (ImplicitReferenceConversionExists (expr_type, target_type))
+                       if (ImplicitReferenceConversionExists (expr_type, target_type, false))
                                return true;
 
                        if (ImplicitBoxingConversion (null, expr_type, target_type) != null)