From 2c810c3ed9592c43ab0734b78e49cd206641e9fe Mon Sep 17 00:00:00 2001 From: Marek Safar Date: Thu, 14 Oct 2010 10:51:17 +0100 Subject: [PATCH] More conversion tweaks for dynamic in using statement --- mcs/errors/cs0029-14.cs | 10 ++++++++++ mcs/errors/cs0509-5.cs | 6 ++++++ mcs/mcs/statement.cs | 5 ++++- mcs/mcs/typespec.cs | 3 +++ mcs/tests/dtest-error-01.cs | 8 ++++++++ mcs/tests/test-577.cs | 16 ++++++++++++++++ mcs/tests/ver-il-dmcs.xml | 38 ++++++++++++++++++++++--------------- 7 files changed, 70 insertions(+), 16 deletions(-) create mode 100644 mcs/errors/cs0029-14.cs create mode 100644 mcs/errors/cs0509-5.cs create mode 100644 mcs/tests/test-577.cs diff --git a/mcs/errors/cs0029-14.cs b/mcs/errors/cs0029-14.cs new file mode 100644 index 00000000000..e0141e92b64 --- /dev/null +++ b/mcs/errors/cs0029-14.cs @@ -0,0 +1,10 @@ +// CS0029: Cannot implicitly convert type `int' to `System.IDisposable' +// Line: 8 + +class A +{ + public static void Main () + { + System.IDisposable id = 1; + } +} diff --git a/mcs/errors/cs0509-5.cs b/mcs/errors/cs0509-5.cs new file mode 100644 index 00000000000..25c7626e275 --- /dev/null +++ b/mcs/errors/cs0509-5.cs @@ -0,0 +1,6 @@ +// CS0509: `X': cannot derive from sealed type `int' +// Line: 4 + +class X : int +{ +} diff --git a/mcs/mcs/statement.cs b/mcs/mcs/statement.cs index 4a3c42f35f2..88bde9ba9be 100644 --- a/mcs/mcs/statement.cs +++ b/mcs/mcs/statement.cs @@ -4871,7 +4871,10 @@ namespace Mono.CSharp { if (initializer == null) return null; - initializer = Convert.ImplicitConversionRequired (bc, initializer, TypeManager.idisposable_type, loc); + // Once there is dynamic used defer conversion to runtime even if we know it will never succeed + Arguments args = new Arguments (1); + args.Add (new Argument (initializer)); + initializer = new DynamicConversion (TypeManager.idisposable_type, 0, args, initializer.Location).Resolve (bc); if (initializer == null) return null; diff --git a/mcs/mcs/typespec.cs b/mcs/mcs/typespec.cs index 16e6564d5c7..99b8919ef35 100644 --- a/mcs/mcs/typespec.cs +++ b/mcs/mcs/typespec.cs @@ -422,6 +422,9 @@ namespace Mono.CSharp public PredefinedTypeSpec (MemberKind kind, string ns, string name) : base (kind, null, null, null, Modifiers.PUBLIC) { + if (kind == MemberKind.Struct) + modifiers |= Modifiers.SEALED; + this.name = name; this.ns = ns; } diff --git a/mcs/tests/dtest-error-01.cs b/mcs/tests/dtest-error-01.cs index d4999c0fc6e..291ad05aad1 100644 --- a/mcs/tests/dtest-error-01.cs +++ b/mcs/tests/dtest-error-01.cs @@ -17,6 +17,14 @@ class Helper class Tester { #pragma warning disable 169 + void Using_1 () + { + AssertError ( + () => { + using (dynamic d = 1) { } + }, "Cannot implicitly convert type `int' to `System.IDisposable'"); + } + void Unsafe_1 () { dynamic d = 1; diff --git a/mcs/tests/test-577.cs b/mcs/tests/test-577.cs new file mode 100644 index 00000000000..b55573a79a9 --- /dev/null +++ b/mcs/tests/test-577.cs @@ -0,0 +1,16 @@ +using System; + +interface IA +{ + event EventHandler e_a, e_b; +} + +class C : IA +{ + event EventHandler IA.e_a { add {} remove {} } + event EventHandler IA.e_b { add {} remove {} } + + public static void Main () + { + } +} \ No newline at end of file diff --git a/mcs/tests/ver-il-dmcs.xml b/mcs/tests/ver-il-dmcs.xml index d50dc82ffe5..fa5216c11fe 100644 --- a/mcs/tests/ver-il-dmcs.xml +++ b/mcs/tests/ver-il-dmcs.xml @@ -1600,7 +1600,7 @@ 404 - 453 + 585 71 @@ -2373,9 +2373,6 @@ - - 110 - 7 @@ -2384,22 +2381,33 @@ 47 - + + 40 + + + 89 + + 105 - + 12 - + 7 - + 7 - + 5 + + + 110 + + @@ -41868,18 +41876,18 @@ - - 7 - - - 53 - 680 28 + + 7 + + + 53 + -- 2.25.1