--- /dev/null
+// CS0266: Cannot implicitly convert type `System.Collections.Generic.IEnumerable<T>' to `System.Collections.Generic.IEnumerable<U>'. An explicit conversion exists (are you missing a cast?)
+// Line: 12
+
+using System;
+using System.Collections.Generic;
+
+public class Test
+{
+ static void Bla<T, U> () where T : U
+ {
+ IEnumerable<T> ita = null;
+ IEnumerable<U> itu = ita;
+ }
+}
// 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)
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:
//
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)
--- /dev/null
+using System;
+using System.Collections.Generic;
+
+public class Test
+{
+ static void Bla<T, U> () where T : class, U
+ {
+ T[] ta = new T[0];
+ IEnumerable<T> ita = ta;
+ IEnumerable<U> itu = ita;
+ }
+
+ static void Main ()
+ {
+ Bla<string, object> ();
+ }
+}
</method>
</type>
</test>
+ <test name="gtest-variance-19.cs">
+ <type name="Test">
+ <method name="Void Bla[T,U]()">
+ <size>12</size>
+ </method>
+ <method name="Void Main()">
+ <size>6</size>
+ </method>
+ <method name="Void .ctor()">
+ <size>7</size>
+ </method>
+ </type>
+ </test>
<test name="gtest-variance-2.cs">
<type name="Foo">
<method name="System.String Bar(System.Object)">