Reduce TLS accesses. (#11487)
[mono-project.git] / mono / tests / iface-contravariant1.cs
blob58570ec5dd243e7ee0882d4a8fc5ec18f3ebe14a
1 using System;
3 /* Test of constrained.callvirt resolution for contravariant interfaces */
6 public interface I<in T>
8 string F (T t);
11 public class C : I<object>
13 public string F (object t)
15 return t.GetType().Name;
19 /* U should be instantiated by a valuetype because we don't want the generic
20 * sharing codepath */
21 public class G<T, TI, U>
22 where TI : I<T>
24 public G(TI i)
26 _i = i;
29 public string Do (T t)
31 // we want to get this in IL:
33 // constrained. !1
34 // callvirt I`1<!T>::F(!0)
36 return _i.F (t);
39 private readonly TI _i;
42 public class Driver
44 public static int Main ()
46 var c = new C();
47 // instantiate with: T=string because we want to be
48 // contravariant with object; U=int because we need a valuetype
49 // to not end up in the generic sharing codepath.
50 var h = new G<string, C, int>(c);
51 var s = h.Do ("abc");
52 var expected = typeof(string).Name;
53 if (s == expected)
54 return 0;
55 else {
56 Console.Error.WriteLine ("Got '{0}', expected '{1}'", s, expected);
57 return 1;