X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mono%2Fmini%2Fgenerics.cs;h=f350710c76e1b04e60e407212595aa47fe84b08b;hb=dd8d450575fabd4282d79ac40fad36727df02621;hp=4c23b39a7c7b2d1d6838e2a88be918d366d464fd;hpb=6f76efaedfbbd4be65d20073b7389c59111cf7d8;p=mono.git diff --git a/mono/mini/generics.cs b/mono/mini/generics.cs index 4c23b39a7c7..f350710c76e 100644 --- a/mono/mini/generics.cs +++ b/mono/mini/generics.cs @@ -2,9 +2,15 @@ using System; using System.Collections.Generic; using System.Linq; using System.Runtime.CompilerServices; - -class Tests { - +using System.Threading; +using System.Threading.Tasks; + +#if MOBILE +class GenericsTests +#else +class Tests +#endif +{ struct TestStruct { public int i; public int j; @@ -15,6 +21,7 @@ class Tests { } } +#if !MOBILE class Enumerator : MyIEnumerator { T MyIEnumerator.Current { get { @@ -32,11 +39,14 @@ class Tests { return true; } } +#endif +#if !MOBILE static int Main (string[] args) { return TestDriver.RunTests (typeof (Tests), args); } +#endif public static int test_1_nullable_unbox () { @@ -181,7 +191,11 @@ class Tests { public static int test_0_constrained_vtype_box () { GenericClass t = new GenericClass (); +#if MOBILE + return t.toString (new TestStruct ()) == "GenericsTests+TestStruct" ? 0 : 1; +#else return t.toString (new TestStruct ()) == "Tests+TestStruct" ? 0 : 1; +#endif } public static int test_0_constrained_vtype () { @@ -308,6 +322,16 @@ class Tests { public GenericClass class_field; } + public class MRO : MarshalByRefObject { + public T gen_field; + + public T stfld_ldfld (T t) { + var m = this; + m.gen_field = t; + return m.gen_field; + } + } + public static int test_0_ldfld_stfld_mro () { MRO m = new MRO (); GenericStruct s = new GenericStruct (5); @@ -330,6 +354,11 @@ class Tests { if (m.class_field.t != 5) return 4; + // gshared + var m2 = new MRO (); + if (m2.stfld_ldfld ("A") != "A") + return 5; + return 0; } @@ -372,6 +401,7 @@ class Tests { return 0; } +#if !MOBILE public static int test_0_variance_reflection () { // covariance on IEnumerator if (!typeof (MyIEnumerator).IsAssignableFrom (typeof (MyIEnumerator))) @@ -394,9 +424,10 @@ class Tests { return 6; return 0; } +#endif public static int test_0_ldvirtftn_generic_method () { - new Tests ().ldvirtftn (); + new GenericsTests ().ldvirtftn (); return the_type == typeof (string) ? 0 : 1; } @@ -527,8 +558,8 @@ class Tests { /* Test that treating arrays as generic collections works with full-aot */ public static int test_0_fullaot_array_wrappers () { - Tests[] arr = new Tests [10]; - enumerate (arr); + GenericsTests[] arr = new GenericsTests [10]; + enumerate (arr); return 0; } @@ -661,9 +692,9 @@ class Tests { } public static int test_0_full_aot_nullable_unbox_from_gshared_code () { - if (!new Tests ().IsNull2 (null)) + if (!new GenericsTests ().IsNull2 (null)) return 1; - if (new Tests ().IsNull2 (new FooStruct ())) + if (new GenericsTests ().IsNull2 (new FooStruct ())) return 2; return 0; } @@ -671,11 +702,11 @@ class Tests { public static int test_0_partial_sharing () { if (PartialShared1 (new List (), 1) != typeof (string)) return 1; - if (PartialShared1 (new List (), 1) != typeof (Tests)) + if (PartialShared1 (new List (), 1) != typeof (GenericsTests)) return 2; if (PartialShared2 (new List (), 1) != typeof (int)) return 3; - if (PartialShared2 (new List (), 1) != typeof (int)) + if (PartialShared2 (new List (), 1) != typeof (int)) return 4; return 0; } @@ -875,6 +906,21 @@ class Tests { return result; } + class SyncClass { + [MethodImpl(MethodImplOptions.Synchronized)] + public Type getInstance() { + return typeof (T); + } + } + + [Category ("GSHAREDVT")] + static int test_0_synchronized_gshared () { + var c = new SyncClass (); + if (c.getInstance () != typeof (string)) + return 1; + return 0; + } + class Response { } @@ -941,4 +987,142 @@ class Tests { return 0; } + + struct Record : Foo2.IRecord { + int counter; + int Foo2.IRecord.DoSomething () { + return counter++; + } + } + + class Foo2 where T : Foo2.IRecord { + public interface IRecord { + int DoSomething (); + } + + public static int Extract (T[] t) { + return t[0].DoSomething (); + } + } + + class Foo3 where T : IComparable { + public static int CompareTo (T[] t) { + // This is a constrained call to Enum.CompareTo () + return t[0].CompareTo (t [0]); + } + } + + public static int test_1_regress_constrained_iface_call_7571 () { + var r = new Record [10]; + Foo2.Extract (r); + return Foo2.Extract (r); + } + + enum ConstrainedEnum { + Val = 1 + } + + public static int test_0_regress_constrained_iface_call_enum () { + var r = new ConstrainedEnum [10]; + return Foo3.CompareTo (r); + } + + public interface IFoo2 { + void MoveNext (); + } + + public struct Foo2 : IFoo2 { + public void MoveNext () { + } + } + + public static Action Dingus (ref Foo2 f) { + return new Action (f.MoveNext); + } + + public static int test_0_delegate_unbox_full_aot () { + Foo2 foo = new Foo2 (); + Dingus (ref foo) (); + return 0; + } + + public static int test_0_arrays_ireadonly () { + int[] arr = new int [10]; + for (int i = 0; i < 10; ++i) + arr [i] = i; + IReadOnlyList a = (IReadOnlyList)(object)arr; + if (a.Count != 10) + return 1; + if (a [0] != 0) + return 2; + if (a [1] != 1) + return 3; + return 0; + } + + public static int test_0_volatile_read_write () { + string foo = "ABC"; + Volatile.Write (ref foo, "DEF"); + return Volatile.Read (ref foo) == "DEF" ? 0 : 1; + } + + // FIXME: Doesn't work with --regression as Interlocked.Add(ref long) is only implemented as an intrinsic +#if FALSE + public static async Task FooAsync (int i, int j) { + Task t = new Task (delegate () { Console.WriteLine ("HIT!"); return 0; }); + var response = await t; + return default(T); + } + + public static int test_0_fullaot_generic_async () { + Task t = FooAsync (1, 2); + t.RunSynchronously (); + return 0; + } +#endif + + public static int test_0_delegate_callvirt_fullaot () { + Func f = delegate () { return "A"; }; + var f2 = (Func, string>)Delegate.CreateDelegate (typeof +(Func, string>), null, f.GetType ().GetMethod ("Invoke")); + + var s = f2 (f); + return s == "A" ? 0 : 1; + } + + public interface ICovariant + { + } + + // Deleting the `out` modifier from this line stop the problem + public interface IExtCovariant : ICovariant + { + } + + public class Sample : ICovariant + { + } + + public interface IMyInterface + { + } + + public static int test_0_variant_cast_cache () { + object covariant = new Sample(); + + var foo = (ICovariant)(covariant); + + try { + var extCovariant = (IExtCovariant)covariant; + return 1; + } catch { + return 0; + } + } +} + +#if !MOBILE +class GenericsTests : Tests +{ } +#endif