Better error reporting for special runtime types
authorMarek Safar <marek.safar@gmail.com>
Fri, 16 Sep 2011 10:56:48 +0000 (11:56 +0100)
committerMarek Safar <marek.safar@gmail.com>
Mon, 19 Sep 2011 10:56:41 +0000 (11:56 +0100)
mcs/errors/cs4012-2.cs [new file with mode: 0644]
mcs/errors/cs4012.cs [new file with mode: 0644]
mcs/errors/cs4013.cs [new file with mode: 0644]
mcs/mcs/class.cs

diff --git a/mcs/errors/cs4012-2.cs b/mcs/errors/cs4012-2.cs
new file mode 100644 (file)
index 0000000..206c89a
--- /dev/null
@@ -0,0 +1,15 @@
+// CS4012: Parameters or local variables of type `System.TypedReference' cannot be declared in async methods or iterators
+// Line: 9
+
+using System;
+using System.Collections;
+
+class C
+{
+       public IEnumerable Iter ()
+       {
+               int i = 2;
+               TypedReference tr = __makeref (i);
+               yield return 1;
+       }
+}
diff --git a/mcs/errors/cs4012.cs b/mcs/errors/cs4012.cs
new file mode 100644 (file)
index 0000000..0176631
--- /dev/null
@@ -0,0 +1,17 @@
+// CS4012: Parameters or local variables of type `System.TypedReference' cannot be declared in async methods or iterators
+// Line: 11
+// Compiler options: -langversion:future
+
+using System;
+using System.Collections;
+using System.Threading.Tasks;
+
+class C
+{
+       public async void Test ()
+       {
+               int i = 2;
+               TypedReference tr = __makeref (i);
+               await Task.Factory.StartNew (() => 6);
+       }
+}
diff --git a/mcs/errors/cs4013.cs b/mcs/errors/cs4013.cs
new file mode 100644 (file)
index 0000000..2ddf470
--- /dev/null
@@ -0,0 +1,17 @@
+// CS1913: Local variables of type `System.TypedReference' cannot be used inside anonymous methods, lambda expressions or query expressions
+// Line: 9
+
+using System;
+
+class C
+{
+       public static void Main ()
+       {
+               int i = 1;
+               TypedReference tr = __makeref (i);
+               {
+                       Action a = () => {      TypedReference tr2 = tr; };
+               }
+       }
+}
+
index 9bf8e7aef7d80ddefc2e87fd06f8088442fe1658..fb526bf21c14dc683120c9b65de86a392a9c9d8f 100644 (file)
@@ -3567,13 +3567,22 @@ namespace Mono.CSharp
                        }
                }
 
-               protected bool IsTypePermitted ()
+               protected void IsTypePermitted ()
                {
                        if (MemberType.IsSpecialRuntimeType) {
-                               Report.Error (610, Location, "Field or property cannot be of type `{0}'", TypeManager.CSharpName (MemberType));
-                               return false;
+                               if (Parent is StateMachine) {
+                                       Report.Error (4012, Location,
+                                               "Parameters or local variables of type `{0}' cannot be declared in async methods or iterators",
+                                               MemberType.GetSignatureForError ());
+                               } else if (Parent is HoistedStoreyClass) {
+                                       Report.Error (4013, Location,
+                                               "Local variables of type `{0}' cannot be used inside anonymous methods, lambda expressions or query expressions",
+                                               MemberType.GetSignatureForError ());
+                               } else {
+                                       Report.Error (610, Location, 
+                                               "Field or property cannot be of type `{0}'", MemberType.GetSignatureForError ());
+                               }
                        }
-                       return true;
                }
 
                protected virtual bool CheckBase ()