+++ /dev/null
-// CS1983: The return type of an async method must be void, Task, or Task<T>
-// Line: 16
-// Compiler options: -langversion:future
-
-using System;
-using System.Threading.Tasks;
-
-class C
-{
- static Task<int> GetInt ()
- {
- return null;
- }
-
- public static void Main ()
- {
- Func<bool> a = async () => { await GetInt (); };
- }
-}
+++ /dev/null
-// CS1983: The return type of an async method must be void, Task, or Task<T>
-// Line: 10
-// Compiler options: -langversion:future
-
-using System;
-
-class C
-{
- public static void Main ()
- {
- Func<string> a = async delegate { };
- }
-}
+++ /dev/null
-// CS1991: Cannot await `void' expression
-// Line: 10
-// Compiler options: -langversion:future
-
-using System;
-
-class A
-{
- static async void Test ()
- {
- await Console.WriteLine ("await");
- }
-}
+++ /dev/null
-// CS1999: The awaiter type `int' must have suitable IsCompleted, OnCompleted, and GetResult members
-// Line: 16
-// Compiler options: -langversion:future
-
-static class S
-{
- public static int GetAwaiter (this int i)
- {
- return 1;
- }
-}
-
-class A
-{
- static async void Test ()
- {
- await 9;
- }
-}
\ No newline at end of file
+++ /dev/null
-// CS1999: The awaiter type `A' must have suitable IsCompleted, OnCompleted, and GetResult members
-// Line: 16
-// Compiler options: -langversion:future
-
-static class S
-{
- public static A GetAwaiter (this int i)
- {
- return new A ();
- }
-}
-
-class A
-{
- int IsCompleted {
- get {
- return 1;
- }
- }
-
- static async void Test ()
- {
- await 9;
- }
-}
+++ /dev/null
-// CS1999: The awaiter type `A' must have suitable IsCompleted, OnCompleted, and GetResult members
-// Line: 16
-// Compiler options: -langversion:future
-
-static class S
-{
- public static A GetAwaiter (this int i)
- {
- return new A ();
- }
-}
-
-class A
-{
- bool IsCompleted {
- get {
- return true;
- }
- }
-
- void OnCompleted (System.Action a)
- {
- }
-
- static async void Test ()
- {
- await 9;
- }
-}
+++ /dev/null
-// CS1999: The awaiter type `int' must have suitable IsCompleted, OnCompleted, and GetResult members
-// Line: 16
-// Compiler options: -langversion:future
-
-static class S
-{
- public static int GetAwaiter (this int i)
- {
- return 1;
- }
-}
-
-class A
-{
- static async void Test ()
- {
- await 9;
- }
-}
\ No newline at end of file
--- /dev/null
+// CS4001: Cannot await `void' expression
+// Line: 10
+// Compiler options: -langversion:future
+
+using System;
+
+class A
+{
+ static async void Test ()
+ {
+ await Console.WriteLine ("await");
+ }
+}
--- /dev/null
+// CS4010: Cannot convert async anonymous method to delegate type `System.Func<string>'
+// Line: 10
+// Compiler options: -langversion:future
+
+using System;
+
+class C
+{
+ public static void Main ()
+ {
+ Func<string> a = async delegate { };
+ }
+}
--- /dev/null
+// CS4010: Cannot convert async lambda expression to delegate type `System.Func<bool>'
+// Line: 16
+// Compiler options: -langversion:future
+
+using System;
+using System.Threading.Tasks;
+
+class C
+{
+ static Task<int> GetInt ()
+ {
+ return null;
+ }
+
+ public static void Main ()
+ {
+ Func<bool> a = async () => { await GetInt (); };
+ }
+}
--- /dev/null
+// CS4011: The awaiter type `int' must have suitable IsCompleted, OnCompleted, and GetResult members
+// Line: 16
+// Compiler options: -langversion:future
+
+static class S
+{
+ public static int GetAwaiter (this int i)
+ {
+ return 1;
+ }
+}
+
+class A
+{
+ static async void Test ()
+ {
+ await 9;
+ }
+}
\ No newline at end of file
--- /dev/null
+// CS4011: The awaiter type `A' must have suitable IsCompleted, OnCompleted, and GetResult members
+// Line: 16
+// Compiler options: -langversion:future
+
+static class S
+{
+ public static A GetAwaiter (this int i)
+ {
+ return new A ();
+ }
+}
+
+class A
+{
+ int IsCompleted {
+ get {
+ return 1;
+ }
+ }
+
+ static async void Test ()
+ {
+ await 9;
+ }
+}
--- /dev/null
+// CS4011: The awaiter type `A' must have suitable IsCompleted, OnCompleted, and GetResult members
+// Line: 16
+// Compiler options: -langversion:future
+
+static class S
+{
+ public static A GetAwaiter (this int i)
+ {
+ return new A ();
+ }
+}
+
+class A
+{
+ bool IsCompleted {
+ get {
+ return true;
+ }
+ }
+
+ void OnCompleted (System.Action a)
+ {
+ }
+
+ static async void Test ()
+ {
+ await 9;
+ }
+}
--- /dev/null
+// CS1999: The awaiter type `int' must have suitable IsCompleted, OnCompleted, and GetResult members
+// Line: 16
+// Compiler options: -langversion:future
+
+static class S
+{
+ public static int GetAwaiter (this int i)
+ {
+ return 1;
+ }
+}
+
+class A
+{
+ static async void Test ()
+ {
+ await 9;
+ }
+}
\ No newline at end of file
}
} else {
if (is_async) {
- AsyncInitializer.Create (ec, body.Block, body.Parameters, ec.CurrentMemberDefinition.Parent, body.ReturnType, loc);
+ var rt = body.ReturnType;
+ if (rt.Kind != MemberKind.Void &&
+ rt != ec.Module.PredefinedTypes.Task.TypeSpec &&
+ !rt.IsGenericTask) {
+ ec.Report.Error (4010, loc, "Cannot convert async {0} to delegate type `{1}'",
+ GetSignatureForError (), type.GetSignatureForError ());
+ }
+
+ AsyncInitializer.Create (ec, body.Block, body.Parameters, ec.CurrentMemberDefinition.Parent, rt, loc);
}
am = body.Compatible (ec);
protected override void Error_TypeDoesNotContainDefinition (ResolveContext rc, TypeSpec type, string name)
{
- Error_WrongGetAwaiter (rc, loc, type);
+ Error_OperatorCannotBeApplied (rc, type);
}
protected override void Error_OperatorCannotBeApplied (ResolveContext rc, TypeSpec type)
{
- rc.Report.Error (1991, loc, "Cannot await `{0}' expression", type.GetSignatureForError ());
+ rc.Report.Error (4001, loc, "Cannot await `{0}' expression", type.GetSignatureForError ());
}
}
}
}
- static void Error_WrongGetAwaiter (ResolveContext rc, Location loc, TypeSpec type)
- {
- rc.Report.Error (1986, loc,
- "The `await' operand type `{0}' must have suitable GetAwaiter method",
- type.GetSignatureForError ());
- }
-
void Error_WrongAwaiterPattern (ResolveContext rc, TypeSpec awaiter)
{
- rc.Report.Error (1999, loc, "The awaiter type `{0}' must have suitable IsCompleted, OnCompleted, and GetResult members",
+ rc.Report.Error (4011, loc, "The awaiter type `{0}' must have suitable IsCompleted, OnCompleted, and GetResult members",
awaiter.GetSignatureForError ());
}
bc.Report.SetPrinter (old);
if (errors_printer.ErrorsCount > 0 || !MemberAccess.IsValidDotExpression (ama.Type)) {
- Error_WrongGetAwaiter (bc, expr.Location, expr.Type);
+ bc.Report.Error (1986, expr.Location,
+ "The `await' operand type `{0}' must have suitable GetAwaiter method",
+ expr.Type.GetSignatureForError ());
+
return false;
}
public static void Create (IMemberContext context, ParametersBlock block, ParametersCompiled parameters, TypeContainer host, TypeSpec returnType, Location loc)
{
- if (returnType != null && returnType.Kind != MemberKind.Void &&
- returnType != host.Module.PredefinedTypes.Task.TypeSpec &&
- !returnType.IsGenericTask) {
- host.Compiler.Report.Error (1983, loc, "The return type of an async method must be void, Task, or Task<T>");
- }
-
for (int i = 0; i < parameters.Count; i++) {
Parameter p = parameters[i];
Parameter.Modifier mod = p.ModFlags;
return "add";
case Token.ASYNC:
return "async";
+ case Token.AWAIT:
+ return "await";
case Token.BASE:
return "base";
case Token.BREAK:
}
if ((ModFlags & Modifiers.ASYNC) != 0) {
+ if (ReturnType.Kind != MemberKind.Void &&
+ ReturnType != Module.PredefinedTypes.Task.TypeSpec &&
+ !ReturnType.IsGenericTask) {
+ Report.Error (1983, Location, "The return type of an async method must be void, Task, or Task<T>");
+ }
+
AsyncInitializer.Create (this, block, parameters, Parent.PartialContainer, ReturnType, Location);
}
}