-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
enable main methods to be asynchronous #18157
Changes from 1 commit
88542e5
909560f
b90d121
2868b64
d7e9e7f
2678fbe
3228961
3d4363a
c3f2482
d88c6e4
c113421
c6c641c
c96708b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1259,7 +1259,13 @@ async static Task Main(string[] args) | |
} | ||
}"; | ||
var compilation = CreateCompilationWithMscorlib45(source, options: TestOptions.DebugExe, parseOptions: TestOptions.Regular.WithLanguageVersion(LanguageVersion.CSharp7)); | ||
compilation.VerifyDiagnostics(Diagnostic(ErrorCode.ERR_MainCantBeAsync, "Main").WithArguments("A.Main(string[])").WithLocation(6, 23)); | ||
compilation.VerifyDiagnostics( | ||
// (6,5): error CS8107: Feature 'async main' is not available in C# 7. Please use language version 7.1 or greater. | ||
// async static Task Main(string[] args) | ||
Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion7, @"async static Task Main(string[] args) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it be possible for the diagnostic to point to a narrow piece of syntax? For example "Main" or maybe "async"? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've added a comment and will get back to this shortly |
||
{ | ||
await Task.Factory.StartNew(() => { }); | ||
}").WithArguments("async main", "7.1").WithLocation(6, 5)); | ||
} | ||
|
||
[Fact] | ||
|
@@ -1325,10 +1331,12 @@ async static void Main() | |
}"; | ||
var compilation = CreateCompilationWithMscorlib45(source, options: TestOptions.DebugExe, parseOptions: TestOptions.Regular.WithLanguageVersion(LanguageVersion.CSharp7)); | ||
compilation.VerifyDiagnostics( | ||
// (6,23): error CS4009: 'A.Main()': an entry point cannot be marked with the 'async' modifier | ||
// (6,5): error CS8107: Feature 'async main' is not available in C# 7. Please use language version 7.1 or greater. | ||
// async static void Main() | ||
Diagnostic(ErrorCode.ERR_MainCantBeAsync, "Main").WithArguments("A.Main()").WithLocation(6, 23) | ||
); | ||
Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion7, @"async static void Main() | ||
{ | ||
await Task.Factory.StartNew(() => { }); | ||
}").WithArguments("async main", "7.1").WithLocation(6, 5)); | ||
} | ||
|
||
[Fact] | ||
|
@@ -1375,10 +1383,14 @@ async static int Main() | |
compilation.VerifyDiagnostics( | ||
// (6,22): error CS1983: The return type of an async method must be void, Task or Task<T> | ||
// async static int Main() | ||
Diagnostic(ErrorCode.ERR_BadAsyncReturn, "Main").WithLocation(6, 22), | ||
// (6,22): error CS4009: 'A.Main()': an entry point cannot be marked with the 'async' modifier | ||
Diagnostic(ErrorCode.ERR_BadAsyncReturn, "Main"), | ||
// (6,5): error CS8107: Feature 'async main' is not available in C# 7. Please use language version 7.1 or greater. | ||
// async static int Main() | ||
Diagnostic(ErrorCode.ERR_MainCantBeAsync, "Main").WithArguments("A.Main()").WithLocation(6, 22)); | ||
Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion7, @"async static int Main() | ||
{ | ||
return await Task.Factory.StartNew(() => 5); | ||
}").WithArguments("async main", "7.1").WithLocation(6, 5) | ||
); | ||
} | ||
|
||
[Fact] | ||
|
@@ -1420,9 +1432,13 @@ async static Task<int> Main(string[] args) | |
}"; | ||
var compilation = CreateCompilationWithMscorlib45(source, options: TestOptions.DebugExe, parseOptions: TestOptions.Regular.WithLanguageVersion(LanguageVersion.CSharp7)); | ||
compilation.VerifyDiagnostics( | ||
// (6,28): error CS4009: 'A.Main(string[])': an entry point cannot be marked with the 'async' modifier | ||
// async static Task<int> Main(string[] args) | ||
Diagnostic(ErrorCode.ERR_MainCantBeAsync, "Main").WithArguments("A.Main(string[])").WithLocation(6, 28)); | ||
// (6,5): error CS8107: Feature 'async main' is not available in C# 7. Please use language version 7.1 or greater. | ||
// async static Task<int> Main(string[] args) | ||
Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion7, @"async static Task<int> Main(string[] args) | ||
{ | ||
return await Task.Factory.StartNew(() => 5); | ||
}").WithArguments("async main", "7.1").WithLocation(6, 5) | ||
); | ||
} | ||
|
||
[Fact] | ||
|
@@ -1464,9 +1480,13 @@ async static Task<int> Main() | |
}"; | ||
var compilation = CreateCompilationWithMscorlib45(source, options: TestOptions.DebugExe, parseOptions: TestOptions.Regular.WithLanguageVersion(LanguageVersion.CSharp7)); | ||
compilation.VerifyDiagnostics( | ||
// (6,28): error CS4009: 'A.Main()': an entry point cannot be marked with the 'async' modifier | ||
// (6,5): error CS8107: Feature 'async main' is not available in C# 7. Please use language version 7.1 or greater. | ||
// async static Task<int> Main() | ||
Diagnostic(ErrorCode.ERR_MainCantBeAsync, "Main").WithArguments("A.Main()").WithLocation(6, 28)); | ||
Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion7, @"async static Task<int> Main() | ||
{ | ||
return await Task.Factory.StartNew(() => 5); | ||
}").WithArguments("async main", "7.1").WithLocation(6, 5) | ||
); | ||
} | ||
|
||
[Fact] | ||
|
@@ -3747,8 +3767,8 @@ async public static Task Main() | |
} | ||
}"; | ||
CreateCompilationWithMscorlib45(source, options: TestOptions.ReleaseExe, parseOptions: TestOptions.Regular.WithLanguageVersion(LanguageVersion.CSharp7_1)).VerifyDiagnostics( | ||
// (4,30): warning CS1998: This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread. | ||
// async public static void Main() | ||
// (5,30): warning CS1998: This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread. | ||
// async public static Task Main() | ||
Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "Main")); | ||
} | ||
|
||
|
@@ -3766,10 +3786,12 @@ async public static Task Main() | |
CreateCompilationWithMscorlib45(source, options: TestOptions.ReleaseExe, parseOptions: TestOptions.Regular.WithLanguageVersion(LanguageVersion.CSharp7)).VerifyDiagnostics( | ||
// (5,30): warning CS1998: This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread. | ||
// async public static Task Main() | ||
Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "Main").WithLocation(5, 30), | ||
// (5,30): error CS4009: 'Test.Main()': an entry point cannot be marked with the 'async' modifier | ||
Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "Main"), | ||
// (5,5): error CS8107: Feature 'async main' is not available in C# 7. Please use language version 7.1 or greater. | ||
// async public static Task Main() | ||
Diagnostic(ErrorCode.ERR_MainCantBeAsync, "Main").WithArguments("Test.Main()").WithLocation(5, 30)); | ||
Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion7, @"async public static Task Main() | ||
{ | ||
}").WithArguments("async main", "7.1").WithLocation(5, 5)); | ||
} | ||
|
||
[Fact, WorkItem(547088, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/547088")] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we delete the corresponding resource string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done