diff --git a/src/Analyzers/CSharp/CodeFixes/CSharpCodeFixes.projitems b/src/Analyzers/CSharp/CodeFixes/CSharpCodeFixes.projitems index 968dd83fb7ec0..6237c865efa18 100644 --- a/src/Analyzers/CSharp/CodeFixes/CSharpCodeFixes.projitems +++ b/src/Analyzers/CSharp/CodeFixes/CSharpCodeFixes.projitems @@ -75,7 +75,6 @@ - @@ -85,8 +84,6 @@ - - @@ -193,4 +190,4 @@ - \ No newline at end of file + diff --git a/src/Analyzers/CSharp/CodeFixes/MakeMethodSynchronous/CSharpMakeMethodSynchronousCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/MakeMethodSynchronous/CSharpMakeMethodSynchronousCodeFixProvider.cs deleted file mode 100644 index de80287f51aa6..0000000000000 --- a/src/Analyzers/CSharp/CodeFixes/MakeMethodSynchronous/CSharpMakeMethodSynchronousCodeFixProvider.cs +++ /dev/null @@ -1,86 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System.Collections.Immutable; -using System.Composition; -using System.Diagnostics.CodeAnalysis; -using Microsoft.CodeAnalysis.CodeFixes; -using Microsoft.CodeAnalysis.CSharp.Extensions; -using Microsoft.CodeAnalysis.CSharp.RemoveAsyncModifier; -using Microsoft.CodeAnalysis.CSharp.Syntax; -using Microsoft.CodeAnalysis.MakeMethodSynchronous; -using Microsoft.CodeAnalysis.Shared.Extensions; - -namespace Microsoft.CodeAnalysis.CSharp.MakeMethodSynchronous; - -using static CSharpSyntaxTokens; - -[ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.MakeMethodSynchronous), Shared] -[ExtensionOrder(After = PredefinedCodeFixProviderNames.AddImport)] -[method: ImportingConstructor] -[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] -internal sealed class CSharpMakeMethodSynchronousCodeFixProvider() : AbstractMakeMethodSynchronousCodeFixProvider -{ - private const string CS1998 = nameof(CS1998); // This async method lacks 'await' operators and will run synchronously. - - public override ImmutableArray FixableDiagnosticIds { get; } = [CS1998]; - - protected override bool IsAsyncSupportingFunctionSyntax(SyntaxNode node) - => node.IsAsyncSupportingFunctionSyntax(); - - protected override SyntaxNode RemoveAsyncTokenAndFixReturnType(IMethodSymbol methodSymbol, SyntaxNode node, KnownTaskTypes knownTypes) - { - switch (node) - { - case MethodDeclarationSyntax method: return FixMethod(methodSymbol, method, knownTypes); - case LocalFunctionStatementSyntax localFunction: return FixLocalFunction(methodSymbol, localFunction, knownTypes); - case AnonymousMethodExpressionSyntax method: return RemoveAsyncModifierHelpers.WithoutAsyncModifier(method); - case ParenthesizedLambdaExpressionSyntax lambda: return RemoveAsyncModifierHelpers.WithoutAsyncModifier(lambda); - case SimpleLambdaExpressionSyntax lambda: return RemoveAsyncModifierHelpers.WithoutAsyncModifier(lambda); - default: return node; - } - } - private static SyntaxNode FixMethod(IMethodSymbol methodSymbol, MethodDeclarationSyntax method, KnownTaskTypes knownTypes) - { - var newReturnType = FixMethodReturnType(methodSymbol, method.ReturnType, knownTypes); - return RemoveAsyncModifierHelpers.WithoutAsyncModifier(method, newReturnType); - } - - private static SyntaxNode FixLocalFunction(IMethodSymbol methodSymbol, LocalFunctionStatementSyntax localFunction, KnownTaskTypes knownTypes) - { - var newReturnType = FixMethodReturnType(methodSymbol, localFunction.ReturnType, knownTypes); - return RemoveAsyncModifierHelpers.WithoutAsyncModifier(localFunction, newReturnType); - } - - private static TypeSyntax FixMethodReturnType(IMethodSymbol methodSymbol, TypeSyntax returnTypeSyntax, KnownTaskTypes knownTypes) - { - var newReturnType = returnTypeSyntax; - - var returnType = methodSymbol.ReturnType; - if (returnType.OriginalDefinition.Equals(knownTypes.TaskType)) - { - // If the return type is Task, then make the new return type "void". - newReturnType = SyntaxFactory.PredefinedType(VoidKeyword).WithTriviaFrom(returnTypeSyntax); - } - else if (returnType.OriginalDefinition.Equals(knownTypes.TaskOfTType)) - { - // If the return type is Task, then make the new return type "T". - newReturnType = returnType.GetTypeArguments()[0].GenerateTypeSyntax().WithTriviaFrom(returnTypeSyntax); - } - else if (returnType.OriginalDefinition.Equals(knownTypes.IAsyncEnumerableOfTType) && - knownTypes.IEnumerableOfTType != null) - { - // If the return type is IAsyncEnumerable, then make the new return type IEnumerable. - newReturnType = knownTypes.IEnumerableOfTType.Construct(methodSymbol.ReturnType.GetTypeArguments()[0]).GenerateTypeSyntax(); - } - else if (returnType.OriginalDefinition.Equals(knownTypes.IAsyncEnumeratorOfTType) && - knownTypes.IEnumeratorOfTType != null) - { - // If the return type is IAsyncEnumerator, then make the new return type IEnumerator. - newReturnType = knownTypes.IEnumeratorOfTType.Construct(methodSymbol.ReturnType.GetTypeArguments()[0]).GenerateTypeSyntax(); - } - - return newReturnType; - } -} diff --git a/src/Analyzers/CSharp/CodeFixes/RemoveAsyncModifier/CSharpRemoveAsyncModifierCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/RemoveAsyncModifier/CSharpRemoveAsyncModifierCodeFixProvider.cs deleted file mode 100644 index 9c5c3e275524b..0000000000000 --- a/src/Analyzers/CSharp/CodeFixes/RemoveAsyncModifier/CSharpRemoveAsyncModifierCodeFixProvider.cs +++ /dev/null @@ -1,66 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System.Collections.Immutable; -using System.Composition; -using System.Diagnostics.CodeAnalysis; -using Microsoft.CodeAnalysis.CodeFixes; -using Microsoft.CodeAnalysis.CSharp.Extensions; -using Microsoft.CodeAnalysis.CSharp.Syntax; -using Microsoft.CodeAnalysis.Editing; -using Microsoft.CodeAnalysis.Formatting; -using Microsoft.CodeAnalysis.RemoveAsyncModifier; - -namespace Microsoft.CodeAnalysis.CSharp.RemoveAsyncModifier; - -using static CSharpSyntaxTokens; - -[ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.RemoveAsyncModifier), Shared] -[ExtensionOrder(After = PredefinedCodeFixProviderNames.MakeMethodSynchronous)] -[method: ImportingConstructor] -[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] -internal sealed partial class CSharpRemoveAsyncModifierCodeFixProvider() : AbstractRemoveAsyncModifierCodeFixProvider -{ - private const string CS1998 = nameof(CS1998); // This async method lacks 'await' operators and will run synchronously. - - public override ImmutableArray FixableDiagnosticIds { get; } = [CS1998]; - - protected override bool IsAsyncSupportingFunctionSyntax(SyntaxNode node) - => node.IsAsyncSupportingFunctionSyntax(); - - protected override SyntaxNode? ConvertToBlockBody(SyntaxNode node, ExpressionSyntax expressionBody) - { - var semicolonToken = SemicolonToken; - if (expressionBody.TryConvertToStatement(semicolonToken, createReturnStatementForExpression: false, out var statement)) - { - var block = SyntaxFactory.Block(statement); - return node switch - { - MethodDeclarationSyntax method => method.WithBody(block).WithExpressionBody(null).WithSemicolonToken(default), - LocalFunctionStatementSyntax localFunction => localFunction.WithBody(block).WithExpressionBody(null).WithSemicolonToken(default), - AnonymousFunctionExpressionSyntax anonymousFunction => anonymousFunction.WithBody(block).WithExpressionBody(null), - _ => throw ExceptionUtilities.Unreachable() - }; - } - - return null; - } - - protected override SyntaxNode RemoveAsyncModifier(SyntaxGenerator generator, SyntaxNode methodLikeNode) - => methodLikeNode switch - { - MethodDeclarationSyntax method => RemoveAsyncModifierHelpers.WithoutAsyncModifier(method, method.ReturnType), - LocalFunctionStatementSyntax localFunction => RemoveAsyncModifierHelpers.WithoutAsyncModifier(localFunction, localFunction.ReturnType), - AnonymousMethodExpressionSyntax method => AnnotateBlock(generator, RemoveAsyncModifierHelpers.WithoutAsyncModifier(method)), - ParenthesizedLambdaExpressionSyntax lambda => AnnotateBlock(generator, RemoveAsyncModifierHelpers.WithoutAsyncModifier(lambda)), - SimpleLambdaExpressionSyntax lambda => AnnotateBlock(generator, RemoveAsyncModifierHelpers.WithoutAsyncModifier(lambda)), - _ => methodLikeNode, - }; - - // Block bodied lambdas and anonymous methods need to be formatted after changing their modifiers, or their indentation is broken - private static SyntaxNode AnnotateBlock(SyntaxGenerator generator, SyntaxNode node) - => generator.GetExpression(node) == null - ? node.WithAdditionalAnnotations(Formatter.Annotation) - : node; -} diff --git a/src/Analyzers/CSharp/CodeFixes/RemoveAsyncModifier/RemoveAsyncModifierHelpers.cs b/src/Analyzers/CSharp/CodeFixes/RemoveAsyncModifier/RemoveAsyncModifierHelpers.cs deleted file mode 100644 index 1df3eefea5e0c..0000000000000 --- a/src/Analyzers/CSharp/CodeFixes/RemoveAsyncModifier/RemoveAsyncModifierHelpers.cs +++ /dev/null @@ -1,64 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using Microsoft.CodeAnalysis.CSharp.Syntax; -using Microsoft.CodeAnalysis.Shared.Extensions; - -namespace Microsoft.CodeAnalysis.CSharp.RemoveAsyncModifier; - -internal static class RemoveAsyncModifierHelpers -{ - internal static SyntaxNode WithoutAsyncModifier(MethodDeclarationSyntax method, TypeSyntax returnType) - { - var newModifiers = RemoveAsyncModifier(method.Modifiers, ref returnType); - return method.WithReturnType(returnType).WithModifiers(newModifiers); - } - - internal static SyntaxNode WithoutAsyncModifier(LocalFunctionStatementSyntax localFunction, TypeSyntax returnType) - { - var newModifiers = RemoveAsyncModifier(localFunction.Modifiers, ref returnType); - return localFunction.WithReturnType(returnType).WithModifiers(newModifiers); - } - - internal static SyntaxNode WithoutAsyncModifier(ParenthesizedLambdaExpressionSyntax lambda) - => lambda.WithAsyncKeyword(default).WithPrependedLeadingTrivia(lambda.AsyncKeyword.LeadingTrivia); - - internal static SyntaxNode WithoutAsyncModifier(SimpleLambdaExpressionSyntax lambda) - => lambda.WithAsyncKeyword(default).WithPrependedLeadingTrivia(lambda.AsyncKeyword.LeadingTrivia); - - internal static SyntaxNode WithoutAsyncModifier(AnonymousMethodExpressionSyntax method) - => method.WithAsyncKeyword(default).WithPrependedLeadingTrivia(method.AsyncKeyword.LeadingTrivia); - - private static SyntaxTokenList RemoveAsyncModifier(SyntaxTokenList modifiers, ref TypeSyntax newReturnType) - { - var asyncTokenIndex = modifiers.IndexOf(SyntaxKind.AsyncKeyword); - SyntaxTokenList newModifiers; - if (asyncTokenIndex == 0) - { - // Have to move the trivia on the async token appropriately. - var asyncLeadingTrivia = modifiers[0].LeadingTrivia; - - if (modifiers.Count > 1) - { - // Move the trivia to the next modifier; - newModifiers = modifiers.Replace( - modifiers[1], - modifiers[1].WithPrependedLeadingTrivia(asyncLeadingTrivia)); - newModifiers = newModifiers.RemoveAt(0); - } - else - { - // move it to the return type. - newModifiers = default; - newReturnType = newReturnType.WithPrependedLeadingTrivia(asyncLeadingTrivia); - } - } - else - { - newModifiers = modifiers.RemoveAt(asyncTokenIndex); - } - - return newModifiers; - } -} diff --git a/src/Analyzers/CSharp/Tests/CSharpAnalyzers.UnitTests.projitems b/src/Analyzers/CSharp/Tests/CSharpAnalyzers.UnitTests.projitems index 72ee2cbca32ab..ea632d2d4b2fc 100644 --- a/src/Analyzers/CSharp/Tests/CSharpAnalyzers.UnitTests.projitems +++ b/src/Analyzers/CSharp/Tests/CSharpAnalyzers.UnitTests.projitems @@ -50,8 +50,6 @@ - - @@ -66,7 +64,6 @@ - @@ -205,4 +202,4 @@ - \ No newline at end of file + diff --git a/src/Analyzers/CSharp/Tests/MakeMethodAsynchronous/MakeMethodAsynchronousTests.cs b/src/Analyzers/CSharp/Tests/MakeMethodAsynchronous/MakeMethodAsynchronousTests.cs deleted file mode 100644 index ac66ce324df27..0000000000000 --- a/src/Analyzers/CSharp/Tests/MakeMethodAsynchronous/MakeMethodAsynchronousTests.cs +++ /dev/null @@ -1,1522 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System.Threading.Tasks; -using Microsoft.CodeAnalysis.CodeFixes; -using Microsoft.CodeAnalysis.CSharp; -using Microsoft.CodeAnalysis.CSharp.MakeMethodAsynchronous; -using Microsoft.CodeAnalysis.Diagnostics; -using Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Diagnostics; -using Microsoft.CodeAnalysis.Test.Utilities; -using Roslyn.Test.Utilities; -using Xunit; -using Xunit.Abstractions; - -namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.MakeMethodAsynchronous; - -[Trait(Traits.Feature, Traits.Features.CodeActionsMakeMethodAsynchronous)] -public sealed partial class MakeMethodAsynchronousTests(ITestOutputHelper logger) - : AbstractCSharpDiagnosticProviderBasedUserDiagnosticTest_NoEditor(logger) -{ - internal override (DiagnosticAnalyzer?, CodeFixProvider) CreateDiagnosticProviderAndFixer(Workspace workspace) - => (null, new CSharpMakeMethodAsynchronousCodeFixProvider()); - - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/33082")] - public Task AwaitInVoidMethodWithModifiers() - => TestInRegularAndScriptAsync(""" - using System; - using System.Threading.Tasks; - - class Program - { - public static void Test() - { - [|await Task.Delay(1);|] - } - } - """, """ - using System; - using System.Threading.Tasks; - - class Program - { - public static async void Test() - { - await Task.Delay(1); - } - } - """, index: 1); - - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/26312")] - public async Task AwaitInTaskMainMethodWithModifiers() - { - var initial = - """ - using System; - using System.Threading.Tasks; - - class Program - { - public static void Main() - { - [|await Task.Delay(1);|] - } - } - """; - await TestAsync(initial, """ - using System; - using System.Threading.Tasks; - - class Program - { - public static async Task Main() - { - await Task.Delay(1); - } - } - """, new(parseOptions: CSharpParseOptions.Default, - compilationOptions: new CSharpCompilationOptions(OutputKind.ConsoleApplication))); - - // no option offered to keep void - await TestActionCountAsync(initial, count: 1, new TestParameters(compilationOptions: new CSharpCompilationOptions(OutputKind.ConsoleApplication))); - } - - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/26312")] - [WorkItem("https://github.com/dotnet/roslyn/issues/33082")] - public Task AwaitInVoidMainMethodWithModifiers_NotEntryPoint() - => TestInRegularAndScriptAsync(""" - using System; - using System.Threading.Tasks; - - class Program - { - public void Main() - { - [|await Task.Delay(1);|] - } - } - """, """ - using System; - using System.Threading.Tasks; - - class Program - { - public async void Main() - { - await Task.Delay(1); - } - } - """, index: 1); - - [Fact] - public Task AwaitInVoidMethodWithModifiers2() - => TestInRegularAndScriptAsync(""" - using System; - using System.Threading.Tasks; - - class Program - { - public static void Test() - { - [|await Task.Delay(1);|] - } - } - """, """ - using System; - using System.Threading.Tasks; - - class Program - { - public static async Task TestAsync() - { - await Task.Delay(1); - } - } - """); - - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/33082")] - public Task AwaitInTaskMethodNoModifiers() - => TestInRegularAndScriptAsync(""" - using System; - using System.Threading.Tasks; - - class Program - { - Task Test() - { - [|await Task.Delay(1);|] - } - } - """, """ - using System; - using System.Threading.Tasks; - - class Program - { - async Task Test() - { - await Task.Delay(1); - } - } - """); - - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/33082")] - public Task AwaitInTaskMethodWithModifiers() - => TestInRegularAndScriptAsync(""" - using System; - using System.Threading.Tasks; - - class Program - { - public/*Comment*/static/*Comment*/Task/*Comment*/Test() - { - [|await Task.Delay(1);|] - } - } - """, """ - using System; - using System.Threading.Tasks; - - class Program - { - public/*Comment*/static/*Comment*/async Task/*Comment*/Test() - { - await Task.Delay(1); - } - } - """); - - [Fact] - public Task AwaitInLambdaFunction() - => TestInRegularAndScriptAsync(""" - using System; - using System.Threading.Tasks; - - class Program - { - static void Main(string[] args) - { - Action a = () => Console.WriteLine(); - Func b = () => [|await Task.Run(a);|] - } - } - """, """ - using System; - using System.Threading.Tasks; - - class Program - { - static void Main(string[] args) - { - Action a = () => Console.WriteLine(); - Func b = async () => await Task.Run(a); - } - } - """); - - [Fact] - public Task AwaitInLambdaAction() - => TestInRegularAndScriptAsync(""" - using System; - using System.Threading.Tasks; - - class Program - { - static void Main(string[] args) - { - Action a = () => [|await Task.Delay(1);|] - } - } - """, """ - using System; - using System.Threading.Tasks; - - class Program - { - static void Main(string[] args) - { - Action a = async () => await Task.Delay(1); - } - } - """); - - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/33082")] - public Task BadAwaitInNonAsyncMethod() - => TestInRegularAndScriptAsync(""" - using System.Threading.Tasks; - class Program - { - void Test() - { - [|await Task.Delay(1);|] - } - } - """, """ - using System.Threading.Tasks; - class Program - { - async void Test() - { - await Task.Delay(1); - } - } - """, index: 1); - - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/33082")] - public Task BadAwaitInNonAsyncMethod2() - => TestInRegularAndScriptAsync(""" - using System.Threading.Tasks; - class Program - { - Task Test() - { - [|await Task.Delay(1);|] - } - } - """, """ - using System.Threading.Tasks; - class Program - { - async Task Test() - { - await Task.Delay(1); - } - } - """); - - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/33082")] - public Task BadAwaitInNonAsyncMethod3() - => TestInRegularAndScriptAsync(""" - using System.Threading.Tasks; - class Program - { - Task Test() - { - [|await Task.Delay(1);|] - } - } - """, """ - using System.Threading.Tasks; - class Program - { - async Task Test() - { - await Task.Delay(1); - } - } - """); - - [Fact] - public Task BadAwaitInNonAsyncMethod4() - => TestInRegularAndScriptAsync(""" - using System.Threading.Tasks; - class Program - { - int Test() - { - [|await Task.Delay(1);|] - } - } - """, """ - using System.Threading.Tasks; - class Program - { - async Task TestAsync() - { - await Task.Delay(1); - } - } - """); - - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/33082")] - public Task BadAwaitInNonAsyncMethod5() - => TestInRegularAndScriptAsync(""" - class Program - { - void Test() - { - [|await Task.Delay(1);|] - } - } - """, """ - class Program - { - async void Test() - { - await Task.Delay(1); - } - } - """, index: 1); - - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/33082")] - public Task BadAwaitInNonAsyncMethod6() - => TestInRegularAndScriptAsync(""" - class Program - { - Task Test() - { - [|await Task.Delay(1);|] - } - } - """, """ - class Program - { - async Task Test() - { - await Task.Delay(1); - } - } - """); - - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/33082")] - public Task BadAwaitInNonAsyncMethod7() - => TestInRegularAndScriptAsync(""" - class Program - { - Task Test() - { - [|await Task.Delay(1);|] - } - } - """, """ - class Program - { - async Task Test() - { - await Task.Delay(1); - } - } - """); - - [Fact] - public Task BadAwaitInNonAsyncMethod8() - => TestInRegularAndScriptAsync(""" - class Program - { - int Test() - { - [|await Task.Delay(1);|] - } - } - """, """ - using System.Threading.Tasks; - - class Program - { - async Task TestAsync() - { - await Task.Delay(1); - } - } - """); - - [Fact] - public Task BadAwaitInNonAsyncMethod9() - => TestInRegularAndScriptAsync(""" - class Program - { - Program Test() - { - [|await Task.Delay(1);|] - } - } - """, """ - using System.Threading.Tasks; - - class Program - { - async Task TestAsync() - { - await Task.Delay(1); - } - } - """); - - [Fact] - public Task BadAwaitInNonAsyncMethod10() - => TestInRegularAndScriptAsync(""" - class Program - { - asdf Test() - { - [|await Task.Delay(1);|] - } - } - """, """ - class Program - { - async System.Threading.Tasks.Task TestAsync() - { - await Task.Delay(1); - } - } - """); - - [Fact] - public async Task BadAwaitInEnumerableMethod() - { - var initial = - """ - using System.Threading.Tasks; - using System.Collections.Generic; - class Program - { - IEnumerable Test() - { - yield return 1; - [|await Task.Delay(1);|] - } - } - """ + IAsyncEnumerable; - - var expected = - """ - using System.Threading.Tasks; - using System.Collections.Generic; - class Program - { - async IAsyncEnumerable TestAsync() - { - yield return 1; - await Task.Delay(1); - } - } - """ + IAsyncEnumerable; - await TestInRegularAndScriptAsync(initial, expected); - } - - [Fact] - public Task BadAwaitInEnumerableMethodMissingIAsyncEnumerableType() - => TestInRegularAndScriptAsync(""" - using System.Threading.Tasks; - using System.Collections.Generic; - class Program - { - IEnumerable Test() - { - yield return 1; - [|await Task.Delay(1);|] - } - } - """, """ - using System.Threading.Tasks; - using System.Collections.Generic; - class Program - { - async IAsyncEnumerable TestAsync() - { - yield return 1; - await Task.Delay(1); - } - } - """); - - [Fact] - public Task BadAwaitInEnumerableMethodWithReturn() - => TestInRegularAndScriptAsync(""" - using System.Threading.Tasks; - using System.Collections.Generic; - class Program - { - IEnumerable Test() - { - [|await Task.Delay(1);|] - return null; - } - } - """, """ - using System.Threading.Tasks; - using System.Collections.Generic; - class Program - { - async Task> TestAsync() - { - await Task.Delay(1); - return null; - } - } - """); - - [Fact] - public Task BadAwaitInEnumerableMethodWithYieldInsideLocalFunction() - => TestInRegularAndScriptAsync(""" - using System.Threading.Tasks; - using System.Collections.Generic; - class Program - { - IEnumerable Test() - { - [|await Task.Delay(1);|] - return local(); - - IEnumerable local() - { - yield return 1; - } - } - } - """, """ - using System.Threading.Tasks; - using System.Collections.Generic; - class Program - { - async Task> TestAsync() - { - await Task.Delay(1); - return local(); - - IEnumerable local() - { - yield return 1; - } - } - } - """); - - [Fact] - public Task BadAwaitInEnumeratorMethodWithReturn() - => TestInRegularAndScriptAsync(""" - using System.Threading.Tasks; - using System.Collections.Generic; - class Program - { - IEnumerator Test() - { - [|await Task.Delay(1);|] - return null; - } - } - """, """ - using System.Threading.Tasks; - using System.Collections.Generic; - class Program - { - async Task> TestAsync() - { - await Task.Delay(1); - return null; - } - } - """); - - [Fact] - public async Task BadAwaitInEnumeratorMethod() - { - var initial = - """ - using System.Threading.Tasks; - using System.Collections.Generic; - class Program - { - IEnumerator Test() - { - yield return 1; - [|await Task.Delay(1);|] - } - } - """ + IAsyncEnumerable; - - var expected = - """ - using System.Threading.Tasks; - using System.Collections.Generic; - class Program - { - async IAsyncEnumerator TestAsync() - { - yield return 1; - await Task.Delay(1); - } - } - """ + IAsyncEnumerable; - await TestInRegularAndScriptAsync(initial, expected); - } - - [Fact] - public async Task BadAwaitInEnumeratorLocalFunction() - { - var initial = - """ - using System.Threading.Tasks; - using System.Collections.Generic; - class Program - { - void M() - { - IEnumerator Test() - { - yield return 1; - [|await Task.Delay(1);|] - } - } - } - """ + IAsyncEnumerable; - - var expected = - """ - using System.Threading.Tasks; - using System.Collections.Generic; - class Program - { - void M() - { - async IAsyncEnumerator TestAsync() - { - yield return 1; - await Task.Delay(1); - } - } - } - """ + IAsyncEnumerable; - await TestInRegularAndScriptAsync(initial, expected); - } - - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/33082")] - public async Task BadAwaitInIAsyncEnumerableMethod() - { - var initial = - """ - using System.Threading.Tasks; - using System.Collections.Generic; - class Program - { - IAsyncEnumerable Test() - { - yield return 1; - [|await Task.Delay(1);|] - } - } - """ + IAsyncEnumerable; - - var expected = - """ - using System.Threading.Tasks; - using System.Collections.Generic; - class Program - { - async IAsyncEnumerable Test() - { - yield return 1; - await Task.Delay(1); - } - } - """ + IAsyncEnumerable; - await TestInRegularAndScriptAsync(initial, expected); - } - - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/33082")] - public async Task BadAwaitInIAsyncEnumeratorMethod() - { - var initial = - """ - using System.Threading.Tasks; - using System.Collections.Generic; - class Program - { - IAsyncEnumerator Test() - { - yield return 1; - [|await Task.Delay(1);|] - } - } - """ + IAsyncEnumerable; - - var expected = - """ - using System.Threading.Tasks; - using System.Collections.Generic; - class Program - { - async IAsyncEnumerator Test() - { - yield return 1; - await Task.Delay(1); - } - } - """ + IAsyncEnumerable; - await TestInRegularAndScriptAsync(initial, expected); - } - - [Fact] - public Task AwaitInMember() - => TestMissingInRegularAndScriptAsync(""" - using System.Threading.Tasks; - - class Program - { - var x = [|await Task.Delay(3)|]; - } - """); - - [Fact] - public Task AddAsyncInDelegate() - => TestInRegularAndScriptAsync( - """ - using System; - using System.Threading.Tasks; - - class Program - { - private async void method() - { - string content = await Task.Run(delegate () { - [|await Task.Delay(1000)|]; - return "Test"; - }); - } - } - """, - """ - using System; - using System.Threading.Tasks; - - class Program - { - private async void method() - { - string content = await Task.Run(async delegate () { - await Task.Delay(1000); - return "Test"; - }); - } - } - """); - - [Fact] - public Task AddAsyncInDelegate2() - => TestInRegularAndScriptAsync( - """ - using System; - using System.Threading.Tasks; - - class Program - { - private void method() - { - string content = await Task.Run(delegate () { - [|await Task.Delay(1000)|]; - return "Test"; - }); - } - } - """, - """ - using System; - using System.Threading.Tasks; - - class Program - { - private void method() - { - string content = await Task.Run(async delegate () { - await Task.Delay(1000); - return "Test"; - }); - } - } - """); - - [Fact] - public Task AddAsyncInDelegate3() - => TestInRegularAndScriptAsync( - """ - using System; - using System.Threading.Tasks; - - class Program - { - private void method() - { - string content = await Task.Run(delegate () { - [|await Task.Delay(1000)|]; - return "Test"; - }); - } - } - """, - """ - using System; - using System.Threading.Tasks; - - class Program - { - private void method() - { - string content = await Task.Run(async delegate () { - await Task.Delay(1000); - return "Test"; - }); - } - } - """); - - [Fact, WorkItem(6477, @"https://github.com/dotnet/roslyn/issues/6477")] - public Task NullNodeCrash() - => TestMissingInRegularAndScriptAsync( - """ - using System.Threading.Tasks; - - class C - { - static async void Main() - { - try - { - [|await|] await Task.Delay(100); - } - finally - { - } - } - } - """); - - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/33082")] - [WorkItem("https://github.com/dotnet/roslyn/issues/17470")] - public Task AwaitInValueTaskMethod() - => TestInRegularAndScriptAsync(""" - using System; - using System.Threading.Tasks; - - namespace System.Threading.Tasks { - struct ValueTask - { - } - } - - class Program - { - ValueTask Test() - { - [|await Task.Delay(1);|] - } - } - """, """ - using System; - using System.Threading.Tasks; - - namespace System.Threading.Tasks { - struct ValueTask - { - } - } - - class Program - { - async ValueTask Test() - { - await Task.Delay(1); - } - } - """); - - [Fact] - public Task AwaitInValueTaskWithoutGenericMethod() - => TestInRegularAndScriptAsync(""" - using System; - using System.Threading.Tasks; - - namespace System.Threading.Tasks { - struct ValueTask - { - } - } - - class Program - { - ValueTask Test() - { - [|await Task.Delay(1);|] - } - } - """, """ - using System; - using System.Threading.Tasks; - - namespace System.Threading.Tasks { - struct ValueTask - { - } - } - - class Program - { - async ValueTask Test() - { - await Task.Delay(1); - } - } - """); - - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/14133")] - public Task AddAsyncInLocalFunction() - => TestInRegularAndScriptAsync( - """ - using System.Threading.Tasks; - - class C - { - public void M1() - { - void M2() - { - [|await M3Async();|] - } - } - - async Task M3Async() - { - return 1; - } - } - """, - """ - using System.Threading.Tasks; - - class C - { - public void M1() - { - async Task M2Async() - { - await M3Async(); - } - } - - async Task M3Async() - { - return 1; - } - } - """); - - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/14133")] - [WorkItem("https://github.com/dotnet/roslyn/issues/33082")] - public Task AddAsyncInLocalFunctionKeepVoidReturn() - => TestInRegularAndScriptAsync( - """ - using System.Threading.Tasks; - - class C - { - public void M1() - { - void M2() - { - [|await M3Async();|] - } - } - - async Task M3Async() - { - return 1; - } - } - """, - """ - using System.Threading.Tasks; - - class C - { - public void M1() - { - async void M2() - { - await M3Async(); - } - } - - async Task M3Async() - { - return 1; - } - } - """, - index: 1); - - [Theory] - [InlineData(0, "void", "Task", "M2Async")] - [InlineData(1, "void", "void", "M2")] - [InlineData(0, "int", "Task", "M2Async")] - [InlineData(0, "Task", "Task", "M2")] - [WorkItem("https://github.com/dotnet/roslyn/issues/18307")] - [WorkItem("https://github.com/dotnet/roslyn/issues/33082")] - public Task AddAsyncInLocalFunctionKeepsTrivia(int codeFixIndex, string initialReturn, string expectedReturn, string expectedName) - => TestInRegularAndScriptAsync( - $$""" - using System.Threading.Tasks; - - class C - { - public void M1() - { - // Leading trivia - /*1*/ {{initialReturn}} /*2*/ M2/*3*/() /*4*/ - { - [|await M3Async();|] - } - } - - async Task M3Async() - { - return 1; - } - } - """, - $$""" - using System.Threading.Tasks; - - class C - { - public void M1() - { - // Leading trivia - /*1*/ async {{expectedReturn}} /*2*/ {{expectedName}}/*3*/() /*4*/ - { - await M3Async(); - } - } - - async Task M3Async() - { - return 1; - } - } - """, - index: codeFixIndex); - - [Theory] - [InlineData("", 0, "Task", "M2Async")] - [InlineData("", 1, "void", "M2")] - [InlineData("public", 0, "Task", "M2Async")] - [InlineData("public", 1, "void", "M2")] - [WorkItem("https://github.com/dotnet/roslyn/issues/18307")] - [WorkItem("https://github.com/dotnet/roslyn/issues/33082")] - public Task AddAsyncKeepsTrivia(string modifiers, int codeFixIndex, string expectedReturn, string expectedName) - => TestInRegularAndScriptAsync( - $$""" - using System.Threading.Tasks; - - class C - { - // Leading trivia - {{modifiers}}/*1*/ void /*2*/ M2/*3*/() /*4*/ - { - [|await M3Async();|] - } - - async Task M3Async() - { - return 1; - } - } - """, - $$""" - using System.Threading.Tasks; - - class C - { - // Leading trivia - {{modifiers}}/*1*/ async {{expectedReturn}} /*2*/ {{expectedName}}/*3*/() /*4*/ - { - await M3Async(); - } - - async Task M3Async() - { - return 1; - } - } - """, - index: codeFixIndex); - - [Fact] - public Task MethodWithAwaitUsing() - => TestInRegularAndScriptAsync( - """ - class C - { - void M() - { - [|await using (var x = new object())|] - { - } - } - } - """, - """ - using System.Threading.Tasks; - - class C - { - async Task MAsync() - { - await using (var x = new object()) - { - } - } - } - """); - - [Fact] - public Task MethodWithRegularUsing() - => TestMissingInRegularAndScriptAsync( - """ - class C - { - void M() - { - [|using (var x = new object())|] - { - } - } - } - """); - - [Fact] - public Task MethodWithAwaitForEach() - => TestInRegularAndScriptAsync( - """ - class C - { - void M() - { - [|await foreach (var n in new int[] { })|] - { - } - } - } - """, - """ - using System.Threading.Tasks; - - class C - { - async Task MAsync() - { - await foreach (var n in new int[] { }) - { - } - } - } - """); - - [Fact] - public Task MethodWithRegularForEach() - => TestMissingInRegularAndScriptAsync( - """ - class C - { - void M() - { - [|foreach (var n in new int[] { })|] - { - } - } - } - """); - - [Fact] - public Task MethodWithAwaitForEachVariable() - => TestInRegularAndScriptAsync( - """ - class C - { - void M() - { - [|await foreach (var (a, b) in new(int, int)[] { })|] - { - } - } - } - """, - """ - using System.Threading.Tasks; - - class C - { - async Task MAsync() - { - await foreach (var (a, b) in new(int, int)[] { }) - { - } - } - } - """); - - [Fact] - public Task MethodWithRegularForEachVariable() - => TestMissingInRegularAndScriptAsync( - """ - class C - { - void M() - { - [|foreach (var (a, b) in new(int, int)[] { })|] - { - } - } - } - """); - - [Fact] - public Task MethodWithNullableReturn() - => TestInRegularAndScriptAsync( - """ - #nullable enable - using System.Threading.Tasks; - class C - { - string? M() - { - [|await Task.Delay(1);|] - return null; - } - } - """, - """ - #nullable enable - using System.Threading.Tasks; - class C - { - async Task MAsync() - { - await Task.Delay(1); - return null; - } - } - """); - - [Fact] - public async Task EnumerableMethodWithNullableType() - { - var initial = - """ - #nullable enable - using System.Threading.Tasks; - using System.Collections.Generic; - class Program - { - IEnumerable Test() - { - yield return string.Empty; - [|await Task.Delay(1);|] - } - } - """ + IAsyncEnumerable; - - var expected = - """ - #nullable enable - using System.Threading.Tasks; - using System.Collections.Generic; - class Program - { - async IAsyncEnumerable TestAsync() - { - yield return string.Empty; - await Task.Delay(1); - } - } - """ + IAsyncEnumerable; - await TestInRegularAndScriptAsync(initial, expected); - } - - [Fact] - public async Task EnumeratorMethodWithNullableType() - { - var initial = - """ - #nullable enable - using System.Threading.Tasks; - using System.Collections.Generic; - class Program - { - IEnumerator Test() - { - yield return string.Empty; - [|await Task.Delay(1);|] - } - } - """ + IAsyncEnumerable; - - var expected = - """ - #nullable enable - using System.Threading.Tasks; - using System.Collections.Generic; - class Program - { - async IAsyncEnumerator TestAsync() - { - yield return string.Empty; - await Task.Delay(1); - } - } - """ + IAsyncEnumerable; - await TestInRegularAndScriptAsync(initial, expected); - } - - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/25446")] - public Task TestOnAwaitParsedAsType() - => TestInRegularAndScriptAsync(""" - using System.Threading.Tasks; - - class C - { - void M() - { - Task task = null; - [|await|] task; - } - } - """, """ - using System.Threading.Tasks; - - class C - { - async Task MAsync() - { - Task task = null; - await task; - } - } - """); - - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/63404")] - public Task PartialMethod1() - => TestInRegularAndScriptAsync(""" - using System.Threading.Tasks; - - public partial class C - { - partial void M(); - } - - public partial class C - { - partial void M() - { - [|await|] Task.Delay(1); - } - } - """, """ - using System.Threading.Tasks; - - public partial class C - { - partial Task MAsync(); - } - - public partial class C - { - async partial Task MAsync() - { - await Task.Delay(1); - } - } - """); - - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/63404")] - public Task PartialMethod2() - => TestInRegularAndScriptAsync(""" - using System.Threading.Tasks; - - public partial class C - { - public partial void M(); - } - - public partial class C - { - public partial void M() - { - [|await|] Task.Delay(1); - } - } - """, """ - using System.Threading.Tasks; - - public partial class C - { - public partial Task MAsync(); - } - - public partial class C - { - public async partial Task MAsync() - { - await Task.Delay(1); - } - } - """); - - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/63404")] - public Task PartialMethod3() - => TestInRegularAndScriptAsync(""" - using System.Threading.Tasks; - - public partial class C - { - partial void M(); - } - - public partial class C - { - partial void M() - { - [|await|] Task.Delay(1); - } - } - """, """ - using System.Threading.Tasks; - - public partial class C - { - partial void M(); - } - - public partial class C - { - async partial void M() - { - await Task.Delay(1); - } - } - """, index: 1); - - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/63404")] - public Task PartialMethod4() - => TestInRegularAndScriptAsync(""" - using System.Threading.Tasks; - - public partial class C - { - public partial void M(); - } - - public partial class C - { - public partial void M() - { - [|await|] Task.Delay(1); - } - } - """, """ - using System.Threading.Tasks; - - public partial class C - { - public partial void M(); - } - - public partial class C - { - public async partial void M() - { - await Task.Delay(1); - } - } - """, index: 1); -} diff --git a/src/Analyzers/CSharp/Tests/MakeMethodSynchronous/MakeMethodSynchronousTests.cs b/src/Analyzers/CSharp/Tests/MakeMethodSynchronous/MakeMethodSynchronousTests.cs deleted file mode 100644 index 2ab8c1bf6b9fa..0000000000000 --- a/src/Analyzers/CSharp/Tests/MakeMethodSynchronous/MakeMethodSynchronousTests.cs +++ /dev/null @@ -1,1045 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System.Threading.Tasks; -using Microsoft.CodeAnalysis.CSharp.MakeMethodSynchronous; -using Microsoft.CodeAnalysis.Editor.UnitTests.CodeActions; -using Microsoft.CodeAnalysis.Test.Utilities; -using Microsoft.CodeAnalysis.Testing; -using Roslyn.Test.Utilities; -using Xunit; - -namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.MakeMethodSynchronous; - -using VerifyCS = CSharpCodeFixVerifier< - EmptyDiagnosticAnalyzer, - CSharpMakeMethodSynchronousCodeFixProvider>; - -[Trait(Traits.Feature, Traits.Features.CodeActionsMakeMethodSynchronous)] -public sealed class MakeMethodSynchronousTests -{ - [Fact] - public Task TestTaskReturnType() - => VerifyCS.VerifyCodeFixAsync( - """ - using System.Threading.Tasks; - - class C - { - async Task {|CS1998:Goo|}() - { - } - } - """, - """ - using System.Threading.Tasks; - - class C - { - void Goo() - { - } - } - """); - - [Fact] - public Task TestTaskOfTReturnType() - => VerifyCS.VerifyCodeFixAsync( - """ - using System.Threading.Tasks; - - class C - { - async Task {|CS1998:Goo|}() - { - return 1; - } - } - """, - """ - using System.Threading.Tasks; - - class C - { - int {|#0:Goo|}() - { - return 1; - } - } - """); - - [Fact] - public Task TestSecondModifier() - => VerifyCS.VerifyCodeFixAsync( - """ - using System.Threading.Tasks; - - class C - { - public async Task {|CS1998:Goo|}() - { - } - } - """, - """ - using System.Threading.Tasks; - - class C - { - public void Goo() - { - } - } - """); - - [Fact] - public Task TestFirstModifier() - => VerifyCS.VerifyCodeFixAsync( - """ - using System.Threading.Tasks; - - class C - { - async public Task {|CS1998:Goo|}() - { - } - } - """, - """ - using System.Threading.Tasks; - - class C - { - public void Goo() - { - } - } - """); - - [Fact] - public Task TestTrailingTrivia() - => VerifyCS.VerifyCodeFixAsync( - """ - using System.Threading.Tasks; - - class C - { - async // comment - Task {|CS1998:Goo|}() - { - } - } - """, - """ - using System.Threading.Tasks; - - class C - { - void Goo() - { - } - } - """); - - [Fact] - public Task TestRenameMethod() - => VerifyCS.VerifyCodeFixAsync( - """ - using System.Threading.Tasks; - - class C - { - async Task {|CS1998:GooAsync|}() - { - } - } - """, - """ - using System.Threading.Tasks; - - class C - { - void Goo() - { - } - } - """); - - [Fact] - public Task TestRenameMethod1() - => VerifyCS.VerifyCodeFixAsync( - """ - using System.Threading.Tasks; - - class C - { - async Task {|CS1998:GooAsync|}() - { - } - - void Bar() - { - GooAsync(); - } - } - """, - """ - using System.Threading.Tasks; - - class C - { - void Goo() - { - } - - void Bar() - { - Goo(); - } - } - """); - - [Fact] - public async Task TestParenthesizedLambda() - { - var expected = - """ - using System; - using System.Threading.Tasks; - - class C - { - void Goo() - { - Func f = - () {|#0:=>|} { }; - } - } - """; - - await new VerifyCS.Test - { - TestCode = """ - using System; - using System.Threading.Tasks; - - class C - { - void Goo() - { - Func f = - async () {|CS1998:=>|} { }; - } - } - """, - FixedState = - { - Sources = { expected }, - ExpectedDiagnostics = - { - // /0/Test0.cs(10,16): error CS1643: Not all code paths return a value in lambda expression of type 'Func' - DiagnosticResult.CompilerError("CS1643").WithLocation(0), - }, - }, - }.RunAsync(); - } - - [Fact] - public async Task TestSimpleLambda() - { - var expected = - """ - using System; - using System.Threading.Tasks; - - class C - { - void Goo() - { - Func f = - a {|#0:=>|} { }; - } - } - """; - - await new VerifyCS.Test - { - TestCode = """ - using System; - using System.Threading.Tasks; - - class C - { - void Goo() - { - Func f = - async a {|CS1998:=>|} { }; - } - } - """, - FixedState = - { - Sources = { expected }, - ExpectedDiagnostics = - { - // /0/Test0.cs(10,15): error CS1643: Not all code paths return a value in lambda expression of type 'Func' - DiagnosticResult.CompilerError("CS1643").WithLocation(0), - }, - }, - }.RunAsync(); - } - - [Fact] - public async Task TestLambdaWithExpressionBody() - { - var expected = - """ - using System; - using System.Threading.Tasks; - - class C - { - void Goo() - { - Func> f = - a => {|#0:1|}; - } - } - """; - - await new VerifyCS.Test - { - TestCode = """ - using System; - using System.Threading.Tasks; - - class C - { - void Goo() - { - Func> f = - async a {|CS1998:=>|} 1; - } - } - """, - FixedState = - { - Sources = { expected }, - ExpectedDiagnostics = - { - // /0/Test0.cs(10,18): error CS0029: Cannot implicitly convert type 'int' to 'System.Threading.Tasks.Task' - DiagnosticResult.CompilerError("CS0029").WithLocation(0).WithArguments("int", "System.Threading.Tasks.Task"), - // /0/Test0.cs(10,18): error CS1662: Cannot convert lambda expression to intended delegate type because some of the return types in the block are not implicitly convertible to the delegate return type - DiagnosticResult.CompilerError("CS1662").WithLocation(0), - }, - }, - }.RunAsync(); - } - - [Fact] - public async Task TestAnonymousMethod() - { - var expected = - """ - using System; - using System.Threading.Tasks; - - class C - { - void Goo() - { - Func f = - {|#0:delegate|} { }; - } - } - """; - - await new VerifyCS.Test - { - TestCode = """ - using System; - using System.Threading.Tasks; - - class C - { - void Goo() - { - Func f = - async {|CS1998:delegate|} { }; - } - } - """, - FixedState = - { - Sources = { expected }, - ExpectedDiagnostics = - { - // /0/Test0.cs(10,13): error CS1643: Not all code paths return a value in anonymous method of type 'Func' - DiagnosticResult.CompilerError("CS1643").WithLocation(0), - }, - }, - }.RunAsync(); - } - - [Fact] - public Task TestFixAll() - => VerifyCS.VerifyCodeFixAsync( - """ - using System.Threading.Tasks; - - public class Class1 - { - async Task {|CS1998:GooAsync|}() - { - BarAsync(); - } - - async Task {|#0:{|CS1998:BarAsync|}|}() - { - GooAsync(); - return 1; - } - } - """, - """ - using System.Threading.Tasks; - - public class Class1 - { - void Goo() - { - Bar(); - } - - int {|#0:Bar|}() - { - Goo(); - return 1; - } - } - """); - - [Fact] - [WorkItem("https://github.com/dotnet/roslyn/issues/13961")] - public async Task TestRemoveAwaitFromCaller1() - { - var expected = - """ - using System.Threading.Tasks; - - public class Class1 - { - void Goo() - { - } - - async void {|CS1998:BarAsync|}() - { - Goo(); - } - } - """; - - await new VerifyCS.Test - { - TestCode = """ - using System.Threading.Tasks; - - public class Class1 - { - async Task {|CS1998:GooAsync|}() - { - } - - async void BarAsync() - { - await GooAsync(); - } - } - """, - FixedState = - { - Sources = { expected }, - MarkupHandling = MarkupMode.Allow, - }, - CodeFixTestBehaviors = CodeFixTestBehaviors.FixOne, - }.RunAsync(); - } - - [Fact] - [WorkItem("https://github.com/dotnet/roslyn/issues/13961")] - public async Task TestRemoveAwaitFromCaller2() - { - var expected = - """ - using System.Threading.Tasks; - - public class Class1 - { - void Goo() - { - } - - async void {|CS1998:BarAsync|}() - { - Goo(); - } - } - """; - - await new VerifyCS.Test - { - TestCode = """ - using System.Threading.Tasks; - - public class Class1 - { - async Task {|CS1998:GooAsync|}() - { - } - - async void BarAsync() - { - await GooAsync().ConfigureAwait(false); - } - } - """, - FixedState = - { - Sources = { expected }, - MarkupHandling = MarkupMode.Allow, - }, - CodeFixTestBehaviors = CodeFixTestBehaviors.FixOne, - }.RunAsync(); - } - - [Fact] - [WorkItem("https://github.com/dotnet/roslyn/issues/13961")] - public async Task TestRemoveAwaitFromCaller3() - { - var expected = - """ - using System.Threading.Tasks; - - public class Class1 - { - void Goo() - { - } - - async void {|CS1998:BarAsync|}() - { - this.Goo(); - } - } - """; - - await new VerifyCS.Test - { - TestCode = """ - using System.Threading.Tasks; - - public class Class1 - { - async Task {|CS1998:GooAsync|}() - { - } - - async void BarAsync() - { - await this.GooAsync(); - } - } - """, - FixedState = - { - Sources = { expected }, - MarkupHandling = MarkupMode.Allow, - }, - CodeFixTestBehaviors = CodeFixTestBehaviors.FixOne, - }.RunAsync(); - } - - [Fact] - [WorkItem("https://github.com/dotnet/roslyn/issues/13961")] - public async Task TestRemoveAwaitFromCaller4() - { - var expected = - """ - using System.Threading.Tasks; - - public class Class1 - { - void Goo() - { - } - - async void {|CS1998:BarAsync|}() - { - this.Goo(); - } - } - """; - - await new VerifyCS.Test - { - TestCode = """ - using System.Threading.Tasks; - - public class Class1 - { - async Task {|CS1998:GooAsync|}() - { - } - - async void BarAsync() - { - await this.GooAsync().ConfigureAwait(false); - } - } - """, - FixedState = - { - Sources = { expected }, - MarkupHandling = MarkupMode.Allow, - }, - CodeFixTestBehaviors = CodeFixTestBehaviors.FixOne, - }.RunAsync(); - } - - [Fact] - [WorkItem("https://github.com/dotnet/roslyn/issues/13961")] - public async Task TestRemoveAwaitFromCallerNested1() - { - var expected = - """ - using System.Threading.Tasks; - - public class Class1 - { - int Goo(int i) - { - return 1; - } - - async void {|CS1998:BarAsync|}() - { - this.Goo(this.Goo(0)); - } - } - """; - - await new VerifyCS.Test - { - TestCode = """ - using System.Threading.Tasks; - - public class Class1 - { - async Task {|CS1998:GooAsync|}(int i) - { - return 1; - } - - async void BarAsync() - { - await this.GooAsync(await this.GooAsync(0)); - } - } - """, - FixedState = - { - Sources = { expected }, - MarkupHandling = MarkupMode.Allow, - }, - CodeFixTestBehaviors = CodeFixTestBehaviors.FixOne, - }.RunAsync(); - } - - [Fact] - [WorkItem("https://github.com/dotnet/roslyn/issues/13961")] - public async Task TestRemoveAwaitFromCallerNested() - { - var expected = - """ - using System.Threading.Tasks; - - public class Class1 - { - int Goo(int i) - { - return 1; - } - - async void {|CS1998:BarAsync|}() - { - this.Goo(this.Goo(0)); - } - } - """; - - await new VerifyCS.Test - { - TestCode = """ - using System.Threading.Tasks; - - public class Class1 - { - async Task {|CS1998:GooAsync|}(int i) - { - return 1; - } - - async void BarAsync() - { - await this.GooAsync(await this.GooAsync(0).ConfigureAwait(false)).ConfigureAwait(false); - } - } - """, - FixedState = - { - Sources = { expected }, - MarkupHandling = MarkupMode.Allow, - }, - CodeFixTestBehaviors = CodeFixTestBehaviors.FixOne, - }.RunAsync(); - } - - [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsMakeMethodAsynchronous)] - [WorkItem("https://github.com/dotnet/roslyn/issues/14133")] - public Task RemoveAsyncInLocalFunction() - => VerifyCS.VerifyCodeFixAsync( - """ - using System.Threading.Tasks; - - class C - { - public void M1() - { - async Task {|CS1998:M2Async|}() - { - } - } - } - """, - """ - using System.Threading.Tasks; - - class C - { - public void M1() - { - void M2() - { - } - } - } - """); - - [Theory] - [InlineData("Task", "C")] - [InlineData("Task", "int")] - [InlineData("Task", "void")] - [InlineData("void", "void")] - [Trait(Traits.Feature, Traits.Features.CodeActionsMakeMethodAsynchronous)] - [WorkItem("https://github.com/dotnet/roslyn/issues/18307")] - public Task RemoveAsyncInLocalFunctionKeepsTrivia(string asyncReturn, string expectedReturn) - => VerifyCS.VerifyCodeFixAsync( - $$""" - using System; - using System.Threading.Tasks; - - class C - { - public void M1() - { - // Leading trivia - /*1*/ async {{asyncReturn}} /*2*/ {|CS1998:M2Async|}/*3*/() /*4*/ - { - throw new NotImplementedException(); - } - } - } - """, - $$""" - using System; - using System.Threading.Tasks; - - class C - { - public void M1() - { - // Leading trivia - /*1*/ - {{expectedReturn}} /*2*/ M2/*3*/() /*4*/ - { - throw new NotImplementedException(); - } - } - } - """); - - [Theory] - [InlineData("", "Task", "\r\n C")] - [InlineData("", "Task", "\r\n int")] - [InlineData("", "Task", "\r\n void")] - [InlineData("", "void", "\r\n void")] - [InlineData("public", "Task", " C")] - [InlineData("public", "Task", " int")] - [InlineData("public", "Task", " void")] - [InlineData("public", "void", " void")] - [Trait(Traits.Feature, Traits.Features.CodeActionsMakeMethodAsynchronous)] - [WorkItem("https://github.com/dotnet/roslyn/issues/18307")] - public Task RemoveAsyncKeepsTrivia(string modifiers, string asyncReturn, string expectedReturn) - => VerifyCS.VerifyCodeFixAsync( - $$""" - using System; - using System.Threading.Tasks; - - class C - { - // Leading trivia - {{modifiers}}/*1*/ async {{asyncReturn}} /*2*/ {|CS1998:M2Async|}/*3*/() /*4*/ - { - throw new NotImplementedException(); - } - } - """, - $$""" - using System; - using System.Threading.Tasks; - - class C - { - // Leading trivia - {{modifiers}}/*1*/{{expectedReturn}} /*2*/ M2/*3*/() /*4*/ - { - throw new NotImplementedException(); - } - } - """); - - [Fact] - public async Task MethodWithUsingAwait() - { - var source = - """ - class C - { - async System.Threading.Tasks.Task MAsync() - { - await using ({|#0:var x = new object()|}) - { - } - } - } - """; - - await new VerifyCS.Test - { - ReferenceAssemblies = ReferenceAssemblies.NetStandard.NetStandard21, - TestCode = source, - ExpectedDiagnostics = - { - // /0/Test0.cs(5,22): error CS8410: 'object': type used in an asynchronous using statement must implement 'System.IAsyncDisposable' or implement a suitable 'DisposeAsync' method. - DiagnosticResult.CompilerError("CS8410").WithLocation(0).WithArguments("object"), - }, - FixedCode = source, - }.RunAsync(); - } - - [Fact] - public Task MethodWithUsingNoAwait() - => VerifyCS.VerifyCodeFixAsync( - """ - class C - { - async System.Threading.Tasks.Task {|CS1998:MAsync|}() - { - using ({|#0:var x = new object()|}) - { - } - } - } - """, - // /0/Test0.cs(5,16): error CS1674: 'object': type used in a using statement must implement 'System.IDisposable'. - DiagnosticResult.CompilerError("CS1674").WithLocation(0).WithArguments("object"), - """ - class C - { - void M() - { - using ({|#0:var x = new object()|}) - { - } - } - } - """); - - [Fact] - public async Task MethodWithAwaitForEach() - { - var source = - """ - class C - { - async System.Threading.Tasks.Task MAsync() - { - await foreach (var n in {|#0:new int[] { }|}) - { - } - } - } - """; - - await VerifyCS.VerifyCodeFixAsync( - source, - // /0/Test0.cs(5,33): error CS1061: 'bool' does not contain a definition for 'GetAwaiter' and no accessible extension method 'GetAwaiter' accepting a first argument of type 'bool' could be found (are you missing a using directive or an assembly reference?) - DiagnosticResult.CompilerError("CS1061").WithLocation(0).WithArguments("bool", "GetAwaiter"), - source); - } - - [Fact] - public Task MethodWithForEachNoAwait() - => VerifyCS.VerifyCodeFixAsync( - """ - class C - { - async System.Threading.Tasks.Task {|CS1998:MAsync|}() - { - foreach (var n in new int[] { }) - { - } - } - } - """, - """ - class C - { - void M() - { - foreach (var n in new int[] { }) - { - } - } - } - """); - - [Fact] - public async Task MethodWithForEachVariableAwait() - { - var source = - """ - class C - { - async System.Threading.Tasks.Task MAsync() - { - await foreach (var (a, b) in {|#0:new(int, int)[] { }|}) - { - } - } - } - """; - - await VerifyCS.VerifyCodeFixAsync( - source, - // /0/Test0.cs(5,38): error CS1061: 'bool' does not contain a definition for 'GetAwaiter' and no accessible extension method 'GetAwaiter' accepting a first argument of type 'bool' could be found (are you missing a using directive or an assembly reference?) - DiagnosticResult.CompilerError("CS1061").WithLocation(0).WithArguments("bool", "GetAwaiter"), - source); - } - - [Fact] - public Task MethodWithForEachVariableNoAwait() - => VerifyCS.VerifyCodeFixAsync( - """ - class C - { - async System.Threading.Tasks.Task {|CS1998:MAsync|}() - { - foreach (var (a, b) in new(int, int)[] { }) - { - } - } - } - """, - """ - class C - { - void M() - { - foreach (var (a, b) in new (int, int)[] { }) - { - } - } - } - """); - - [Fact] - public Task TestIAsyncEnumerableReturnType() - => new VerifyCS.Test - { - ReferenceAssemblies = ReferenceAssemblies.NetStandard.NetStandard21, - TestCode = """ - using System.Threading.Tasks; - using System.Collections.Generic; - - class C - { - async IAsyncEnumerable {|CS1998:MAsync|}() - { - yield return 1; - } - } - """, - FixedCode = """ - using System.Threading.Tasks; - using System.Collections.Generic; - - class C - { - IEnumerable M() - { - yield return 1; - } - } - """, - }.RunAsync(); - - [Fact] - public Task TestIAsyncEnumeratorReturnTypeOnLocalFunction() - => new VerifyCS.Test - { - ReferenceAssemblies = ReferenceAssemblies.NetStandard.NetStandard21, - TestCode = """ - using System.Threading.Tasks; - using System.Collections.Generic; - - class C - { - void Method() - { - async IAsyncEnumerator {|CS1998:MAsync|}() - { - yield return 1; - } - } - } - """, - FixedCode = """ - using System.Threading.Tasks; - using System.Collections.Generic; - - class C - { - void Method() - { - IEnumerator M() - { - yield return 1; - } - } - } - """, - }.RunAsync(); -} diff --git a/src/Analyzers/CSharp/Tests/RemoveAsyncModifier/RemoveAsyncModifierTests.cs b/src/Analyzers/CSharp/Tests/RemoveAsyncModifier/RemoveAsyncModifierTests.cs deleted file mode 100644 index 59c4359e89360..0000000000000 --- a/src/Analyzers/CSharp/Tests/RemoveAsyncModifier/RemoveAsyncModifierTests.cs +++ /dev/null @@ -1,1224 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System.Threading.Tasks; -using Microsoft.CodeAnalysis.CSharp.RemoveAsyncModifier; -using Microsoft.CodeAnalysis.CSharp.Test.Utilities; -using Microsoft.CodeAnalysis.Editor.UnitTests.CodeActions; -using Microsoft.CodeAnalysis.Test.Utilities; -using Microsoft.CodeAnalysis.Testing; -using Roslyn.Test.Utilities; -using Xunit; - -namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.RemoveAsyncModifier; - -using VerifyCS = CSharpCodeFixVerifier< - EmptyDiagnosticAnalyzer, - CSharpRemoveAsyncModifierCodeFixProvider>; - -[Trait(Traits.Feature, Traits.Features.CodeActionsRemoveAsyncModifier)] -public sealed class RemoveAsyncModifierTests -{ - [Fact] - public Task Method_Task_MultipleAndNested() - => VerifyCS.VerifyCodeFixAsync( - """ - using System; - using System.Threading.Tasks; - - class C - { - async Task {|CS1998:Goo|}() - { - if (DateTime.Now.Ticks > 0) - { - return; - } - } - - async Task {|CS1998:Foo|}() - { - Console.WriteLine(1); - } - - async Task {|CS1998:Bar|}() - { - async Task {|CS1998:Baz|}() - { - Func> g = async () {|CS1998:=>|} 5; - } - } - - async Task {|CS1998:Tur|}() - { - async Task {|CS1998:Duck|}() - { - async Task {|CS1998:En|}() - { - return "Developers!"; - } - - return "Developers! Developers!"; - } - - return "Developers! Developers! Developers!"; - } - - async Task {|CS1998:Nurk|}() - { - Func> f = async () {|CS1998:=>|} 4; - - if (DateTime.Now.Ticks > f().Result) - { - } - } - } - """, - """ - using System; - using System.Threading.Tasks; - - class C - { - Task Goo() - { - if (DateTime.Now.Ticks > 0) - { - return Task.CompletedTask; - } - - return Task.CompletedTask; - } - - Task Foo() - { - Console.WriteLine(1); - return Task.CompletedTask; - } - - Task Bar() - { - Task Baz() - { - Func> g = () => Task.FromResult(5); - return Task.CompletedTask; - } - - return Task.CompletedTask; - } - - Task Tur() - { - Task Duck() - { - Task En() - { - return Task.FromResult("Developers!"); - } - - return Task.FromResult("Developers! Developers!"); - } - - return Task.FromResult("Developers! Developers! Developers!"); - } - - Task Nurk() - { - Func> f = () => Task.FromResult(4); - - if (DateTime.Now.Ticks > f().Result) - { - } - - return Task.CompletedTask; - } - } - """); - - [Fact] - public Task Method_Task_EmptyBlockBody() - => VerifyCS.VerifyCodeFixAsync( - """ - using System.Threading.Tasks; - - class C - { - async Task {|CS1998:Goo|}(){} - } - """, - """ - using System.Threading.Tasks; - - class C - { - Task Goo() - { - return Task.CompletedTask; - } - } - """); - - [Fact] - public Task Method_Task_BlockBody() - => VerifyCS.VerifyCodeFixAsync( - """ - using System.Threading.Tasks; - - class C - { - async Task {|CS1998:Goo|}() - { - if (System.DateTime.Now.Ticks > 0) - { - return; - } - } - } - """, - """ - using System.Threading.Tasks; - - class C - { - Task Goo() - { - if (System.DateTime.Now.Ticks > 0) - { - return Task.CompletedTask; - } - - return Task.CompletedTask; - } - } - """); - - [Fact] - public Task Method_ValueTask_BlockBody() - => new VerifyCS.Test - { - ReferenceAssemblies = ReferenceAssemblies.NetStandard.NetStandard21, - TestCode = """ - using System.Threading.Tasks; - - class C - { - async ValueTask {|CS1998:Goo|}() - { - if (System.DateTime.Now.Ticks > 0) - { - return; - } - } - } - """, - FixedCode = """ - using System.Threading.Tasks; - - class C - { - ValueTask Goo() - { - if (System.DateTime.Now.Ticks > 0) - { - return new ValueTask(); - } - - return new ValueTask(); - } - } - """, - }.RunAsync(); - - [Fact] - public Task Method_ValueTaskOfT_BlockBody() - => new VerifyCS.Test - { - ReferenceAssemblies = ReferenceAssemblies.NetStandard.NetStandard21, - TestCode = """ - using System.Threading.Tasks; - - class C - { - async ValueTask {|CS1998:Goo|}() - { - if (System.DateTime.Now.Ticks > 0) - { - return 2; - } - - return 3; - } - } - """, - FixedCode = """ - using System.Threading.Tasks; - - class C - { - ValueTask Goo() - { - if (System.DateTime.Now.Ticks > 0) - { - return new ValueTask(2); - } - - return new ValueTask(3); - } - } - """, - }.RunAsync(); - - [Fact] - public Task Method_ValueTask_ExpressionBody() - => new VerifyCS.Test - { - ReferenceAssemblies = ReferenceAssemblies.NetStandard.NetStandard21, - TestCode = """ - using System.Threading.Tasks; - - class C - { - async ValueTask {|CS1998:Goo|}() => System.Console.WriteLine(1); - } - """, - FixedCode = """ - using System.Threading.Tasks; - - class C - { - ValueTask Goo() - { - System.Console.WriteLine(1); - return new ValueTask(); - } - } - """, - }.RunAsync(); - - [Fact] - public Task Method_ValueTaskOfT_ExpressionBody() - => new VerifyCS.Test - { - ReferenceAssemblies = ReferenceAssemblies.NetStandard.NetStandard21, - TestCode = """ - using System.Threading.Tasks; - - class C - { - async ValueTask {|CS1998:Goo|}() => 3; - } - """, - FixedCode = """ - using System.Threading.Tasks; - - class C - { - ValueTask Goo() => new ValueTask(3); - } - """, - }.RunAsync(); - - [Fact] - public Task Method_Task_BlockBody_Throws() - => VerifyCS.VerifyCodeFixAsync( - """ - using System.Threading.Tasks; - - class C - { - async Task {|CS1998:Goo|}() - { - if (System.DateTime.Now.Ticks > 0) - { - return; - } - - throw new System.ApplicationException(); - } - } - """, - """ - using System.Threading.Tasks; - - class C - { - Task Goo() - { - if (System.DateTime.Now.Ticks > 0) - { - return Task.CompletedTask; - } - - throw new System.ApplicationException(); - } - } - """); - - [Fact] - public Task Method_Task_BlockBody_WithLocalFunction() - => VerifyCS.VerifyCodeFixAsync( - """ - using System.Threading.Tasks; - - class C - { - async Task {|CS1998:Goo|}() - { - if (GetTicks() > 0) - { - return; - } - - long GetTicks() - { - return System.DateTime.Now.Ticks; - } - } - } - """, - """ - using System.Threading.Tasks; - - class C - { - Task Goo() - { - if (GetTicks() > 0) - { - return Task.CompletedTask; - } - - long GetTicks() - { - return System.DateTime.Now.Ticks; - } - - return Task.CompletedTask; - } - } - """); - - [Fact] - public Task Method_Task_BlockBody_WithLambda() - => VerifyCS.VerifyCodeFixAsync( - """ - using System.Threading.Tasks; - - class C - { - async Task {|CS1998:Goo|}() - { - System.Func getTicks = () => { - return System.DateTime.Now.Ticks; - }; - - if (getTicks() > 0) - { - return; - } - - } - } - """, - """ - using System.Threading.Tasks; - - class C - { - Task Goo() - { - System.Func getTicks = () => { - return System.DateTime.Now.Ticks; - }; - - if (getTicks() > 0) - { - return Task.CompletedTask; - } - - return Task.CompletedTask; - } - } - """); - - [Fact] - public Task Method_TaskOfT_BlockBody() - => VerifyCS.VerifyCodeFixAsync( - """ - using System.Threading.Tasks; - - class C - { - async Task {|CS1998:Goo|}() - { - if (System.DateTime.Now.Ticks > 0) - { - return 2; - } - - return 3; - } - } - """, - """ - using System.Threading.Tasks; - - class C - { - Task Goo() - { - if (System.DateTime.Now.Ticks > 0) - { - return Task.FromResult(2); - } - - return Task.FromResult(3); - } - } - """); - - [Fact] - public Task Method_TaskOfT_ExpressionBody() - => VerifyCS.VerifyCodeFixAsync( - """ - using System.Threading.Tasks; - - class C - { - async Task {|CS1998:Goo|}() => 2; - } - """, - """ - using System.Threading.Tasks; - - class C - { - Task Goo() => Task.FromResult(2); - } - """); - - [Fact] - public Task Method_Task_ExpressionBody() - => VerifyCS.VerifyCodeFixAsync( - """ - using System; - using System.Threading.Tasks; - - class C - { - async Task {|CS1998:Goo|}() => Console.WriteLine("Hello"); - } - """, - """ - using System; - using System.Threading.Tasks; - - class C - { - Task Goo() - { - Console.WriteLine("Hello"); - return Task.CompletedTask; - } - } - """); - - [Fact] - public Task LocalFunction_Task_BlockBody() - => VerifyCS.VerifyCodeFixAsync( - """ - using System.Threading.Tasks; - - class C - { - public void M1() - { - async Task {|CS1998:Goo|}() - { - if (System.DateTime.Now.Ticks > 0) - { - return; - } - } - } - } - """, - """ - using System.Threading.Tasks; - - class C - { - public void M1() - { - Task Goo() - { - if (System.DateTime.Now.Ticks > 0) - { - return Task.CompletedTask; - } - - return Task.CompletedTask; - } - } - } - """); - - [Fact] - public Task LocalFunction_Task_ExpressionBody() - => VerifyCS.VerifyCodeFixAsync( - """ - using System; - using System.Threading.Tasks; - - class C - { - public void M1() - { - async Task {|CS1998:Goo|}() => Console.WriteLine(1); - } - } - """, - """ - using System; - using System.Threading.Tasks; - - class C - { - public void M1() - { - Task Goo() { Console.WriteLine(1); return Task.CompletedTask; } - } - } - """); - - [Fact] - public Task LocalFunction_TaskOfT_BlockBody() - => VerifyCS.VerifyCodeFixAsync( - """ - using System.Threading.Tasks; - - class C - { - public void M1() - { - async Task {|CS1998:Goo|}() - { - return 1; - } - } - } - """, - """ - using System.Threading.Tasks; - - class C - { - public void M1() - { - Task Goo() - { - return Task.FromResult(1); - } - } - } - """); - - [Fact] - public Task LocalFunction_TaskOfT_ExpressionBody() - => VerifyCS.VerifyCodeFixAsync( - """ - using System.Threading.Tasks; - - class C - { - public void M1() - { - async Task {|CS1998:Goo|}() => 1; - } - } - """, - """ - using System.Threading.Tasks; - - class C - { - public void M1() - { - Task Goo() => Task.FromResult(1); - } - } - """); - - [Fact] - public Task AnonymousFunction_Task_BlockBody() - => VerifyCS.VerifyCodeFixAsync( - """ - using System; - using System.Threading.Tasks; - - class C - { - public void M1() - { - Func foo = (Func)async {|CS1998:delegate|} { - if (System.DateTime.Now.Ticks > 0) - { - return; - } - }; - } - } - """, - """ - using System; - using System.Threading.Tasks; - - class C - { - public void M1() - { - Func foo = (Func)delegate - { - if (System.DateTime.Now.Ticks > 0) - { - return Task.CompletedTask; - } - - return Task.CompletedTask; - }; - } - } - """); - - [Fact] - public Task AnonymousFunction_TaskOfT_BlockBody() - => VerifyCS.VerifyCodeFixAsync( - """ - using System; - using System.Threading.Tasks; - - class C - { - public void M1() - { - Func> foo = (Func>)async {|CS1998:delegate|} - { - return 1; - }; - } - } - """, - """ - using System; - using System.Threading.Tasks; - - class C - { - public void M1() - { - Func> foo = (Func>)delegate - { - return Task.FromResult(1); - }; - } - } - """); - - [Fact] - public Task SimpleLambda_TaskOfT_ExpressionBody() - => VerifyCS.VerifyCodeFixAsync( - """ - using System; - using System.Threading.Tasks; - - class C - { - public void M1() - { - Func> foo = async x {|CS1998:=>|} 1; - } - } - """, - """ - using System; - using System.Threading.Tasks; - - class C - { - public void M1() - { - Func> foo = x => Task.FromResult(1); - } - } - """); - - [Fact] - public Task SimpleLambda_TaskOfT_BlockBody() - => VerifyCS.VerifyCodeFixAsync( - """ - using System; - using System.Threading.Tasks; - - class C - { - public void M1() - { - Func> foo = async x {|CS1998:=>|} { - return 1; - }; - } - } - """, - """ - using System; - using System.Threading.Tasks; - - class C - { - public void M1() - { - Func> foo = x => - { - return Task.FromResult(1); - }; - } - } - """); - - [Fact] - public Task SimpleLambda_Task_ExpressionBody() - => VerifyCS.VerifyCodeFixAsync( - """ - using System; - using System.Threading.Tasks; - - class C - { - public void M1() - { - Func foo = async x {|CS1998:=>|} Console.WriteLine(1); - } - } - """, - """ - using System; - using System.Threading.Tasks; - - class C - { - public void M1() - { - Func foo = x => { Console.WriteLine(1); return Task.CompletedTask; }; - } - } - """); - - [Fact] - public Task SimpleLambda_Task_BlockBody() - => VerifyCS.VerifyCodeFixAsync( - """ - using System; - using System.Threading.Tasks; - - class C - { - public void M1() - { - Func foo = async x {|CS1998:=>|} - { - if (System.DateTime.Now.Ticks > 0) - { - return; - } - }; - } - } - """, - """ - using System; - using System.Threading.Tasks; - - class C - { - public void M1() - { - Func foo = x => - { - if (System.DateTime.Now.Ticks > 0) - { - return Task.CompletedTask; - } - - return Task.CompletedTask; - }; - } - } - """); - - [Fact] - public Task ParenthesizedLambda_TaskOfT_ExpressionBody() - => VerifyCS.VerifyCodeFixAsync( - """ - using System; - using System.Threading.Tasks; - - class C - { - public void M1() - { - Func> foo = async () {|CS1998:=>|} 1; - } - } - """, - """ - using System; - using System.Threading.Tasks; - - class C - { - public void M1() - { - Func> foo = () => Task.FromResult(1); - } - } - """); - - [Fact] - public Task ParenthesizedLambda_TaskOfT_BlockBody() - => VerifyCS.VerifyCodeFixAsync( - """ - using System; - using System.Threading.Tasks; - - class C - { - public void M1() - { - Func> foo = async () {|CS1998:=>|} { - return 1; - }; - } - } - """, - """ - using System; - using System.Threading.Tasks; - - class C - { - public void M1() - { - Func> foo = () => - { - return Task.FromResult(1); - }; - } - } - """); - - [Fact] - public Task ParenthesizedLambda_Task_ExpressionBody() - => VerifyCS.VerifyCodeFixAsync( - """ - using System; - using System.Threading.Tasks; - - class C - { - public void M1() - { - Func foo = async () {|CS1998:=>|} Console.WriteLine(1); - } - } - """, - """ - using System; - using System.Threading.Tasks; - - class C - { - public void M1() - { - Func foo = () => { Console.WriteLine(1); return Task.CompletedTask; }; - } - } - """); - - [Fact] - public Task ParenthesizedLambda_Task_BlockBody() - => VerifyCS.VerifyCodeFixAsync( - """ - using System; - using System.Threading.Tasks; - - class C - { - public void M1() - { - Func foo = async () {|CS1998:=>|} - { - if (System.DateTime.Now.Ticks > 0) - { - return; - } - }; - } - } - """, - """ - using System; - using System.Threading.Tasks; - - class C - { - public void M1() - { - Func foo = () => - { - if (System.DateTime.Now.Ticks > 0) - { - return Task.CompletedTask; - } - - return Task.CompletedTask; - }; - } - } - """); - - [Fact] - public Task Method_Task_BlockBody_FullyQualified() - => VerifyCS.VerifyCodeFixAsync( - """ - class C - { - async System.Threading.Tasks.Task {|CS1998:Goo|}() - { - if (System.DateTime.Now.Ticks > 0) - { - return; - } - } - } - """, - """ - class C - { - System.Threading.Tasks.Task Goo() - { - if (System.DateTime.Now.Ticks > 0) - { - return System.Threading.Tasks.Task.CompletedTask; - } - - return System.Threading.Tasks.Task.CompletedTask; - } - } - """); - - [Fact] - public Task Method_TaskOfT_BlockBody_FullyQualified() - => VerifyCS.VerifyCodeFixAsync( - """ - class C - { - async System.Threading.Tasks.Task {|CS1998:Goo|}() - { - if (System.DateTime.Now.Ticks > 0) - { - return 1; - } - - return 2; - } - } - """, - """ - class C - { - System.Threading.Tasks.Task Goo() - { - if (System.DateTime.Now.Ticks > 0) - { - return System.Threading.Tasks.Task.FromResult(1); - } - - return System.Threading.Tasks.Task.FromResult(2); - } - } - """); - - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/65536")] - public Task Method_TaskOfT_BlockBody_QualifyTaskFromResultType() - => VerifyCS.VerifyCodeFixAsync(""" - using System.Threading.Tasks; - using System.Collections.Generic; - - class C - { - public async Task> {|CS1998:M|}() - { - return new int[0]; - } - } - """, """ - using System.Threading.Tasks; - using System.Collections.Generic; - - class C - { - public Task> M() - { - return Task.FromResult>(new int[0]); - } - } - """); - - [Fact] - public async Task IAsyncEnumerable_Missing() - { - var source = """ - using System.Threading.Tasks; - using System.Collections.Generic; - - class C - { - async IAsyncEnumerable M() - { - yield return 1; - } - } - """ + CSharpTestBase.AsyncStreamsTypes; - - await new VerifyCS.Test - { - ReferenceAssemblies = ReferenceAssemblies.NetStandard.NetStandard21, - TestCode = source, - ExpectedDiagnostics = - { - // /0/Test0.cs(7,33): 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. - DiagnosticResult.CompilerWarning("CS1998").WithSpan(6, 33, 6, 34), - }, - FixedCode = source, - }.RunAsync(); - } - - [Fact] - public async Task Method_AsyncVoid_Missing() - { - var source = """ - using System.Threading.Tasks; - - class C - { - async void M() - { - System.Console.WriteLine(1); - } - } - """; - - await new VerifyCS.Test - { - ReferenceAssemblies = ReferenceAssemblies.NetStandard.NetStandard21, - TestCode = source, - ExpectedDiagnostics = - { - // /0/Test0.cs(6,16): 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. - DiagnosticResult.CompilerWarning("CS1998").WithSpan(5, 16, 5, 17), - }, - FixedCode = source, - }.RunAsync(); - } - - [Fact] - public async Task ParenthesizedLambda_AsyncVoid_Missing() - { - var source = """ - using System; - using System.Threading.Tasks; - - class C - { - void M() - { - Action a = async () => Console.WriteLine(1); - } - } - """; - - await new VerifyCS.Test - { - ReferenceAssemblies = ReferenceAssemblies.NetStandard.NetStandard21, - TestCode = source, - ExpectedDiagnostics = - { - // /0/Test0.cs(9,29): 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. - DiagnosticResult.CompilerWarning("CS1998").WithSpan(8, 29, 8, 31), - }, - FixedCode = source, - }.RunAsync(); - } - - [Fact] - public async Task SimpleLambda_AsyncVoid_Missing() - { - var source = """ - using System; - using System.Threading.Tasks; - - class C - { - void M() - { - Action a = async x => Console.WriteLine(x); - } - } - """; - - await new VerifyCS.Test - { - ReferenceAssemblies = ReferenceAssemblies.NetStandard.NetStandard21, - TestCode = source, - ExpectedDiagnostics = - { - // /0/Test0.cs(9,33): 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. - DiagnosticResult.CompilerWarning("CS1998").WithSpan(8, 33, 8, 35), - }, - FixedCode = source, - }.RunAsync(); - } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/65380")] - public Task TestCloseBraceTrivia() - => VerifyCS.VerifyCodeFixAsync( - """ - using System; - using System.Threading.Tasks; - - public class Class1 - { - public async Task {|CS1998:Goo|}() - { - //Hello - Console.WriteLine("Goo"); - //World - } - } - """, - """ - using System; - using System.Threading.Tasks; - - public class Class1 - { - public Task Goo() - { - //Hello - Console.WriteLine("Goo"); - return Task.CompletedTask; - //World - } - } - """); -} diff --git a/src/Analyzers/Core/CodeFixes/UseAutoProperty/AbstractUseAutoPropertyCodeFixProvider.cs b/src/Analyzers/Core/CodeFixes/UseAutoProperty/AbstractUseAutoPropertyCodeFixProvider.cs index 7ef21eba865d1..28b0e34db30ba 100644 --- a/src/Analyzers/Core/CodeFixes/UseAutoProperty/AbstractUseAutoPropertyCodeFixProvider.cs +++ b/src/Analyzers/Core/CodeFixes/UseAutoProperty/AbstractUseAutoPropertyCodeFixProvider.cs @@ -515,6 +515,7 @@ private static async ValueTask IsWrittenToOutsideOfConstructorOrPropertyAs // We do need a setter return true; + // Remove after .NET 10, https://github.com/dotnet/roslyn/issues/80198 #pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously async ValueTask IsWrittenToAsync(ReferenceLocation loc) { diff --git a/src/Compilers/CSharp/Portable/CSharpResources.resx b/src/Compilers/CSharp/Portable/CSharpResources.resx index 4987775354d49..6d4974fc38042 100644 --- a/src/Compilers/CSharp/Portable/CSharpResources.resx +++ b/src/Compilers/CSharp/Portable/CSharpResources.resx @@ -3833,12 +3833,6 @@ Give the compiler some way to differentiate the methods. For example, you can gi The 'await' operator may only be used in a query expression within the first collection expression of the initial 'from' clause or within the collection expression of a 'join' clause - - 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 method lacks 'await' operators and will run synchronously - Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call. diff --git a/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs b/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs index d231de7a68dc8..8ec23581e5a27 100644 --- a/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs +++ b/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs @@ -1024,7 +1024,7 @@ internal enum ErrorCode ERR_BadAwaitInQuery = 1995, ERR_BadAwaitInLock = 1996, ERR_TaskRetNoObjectRequired = 1997, - WRN_AsyncLacksAwaits = 1998, + // WRN_AsyncLacksAwaits = 1998, ERR_FileNotFound = 2001, WRN_FileAlreadyIncluded = 2002, //ERR_DuplicateResponseFile = 2003, diff --git a/src/Compilers/CSharp/Portable/Errors/ErrorFacts.cs b/src/Compilers/CSharp/Portable/Errors/ErrorFacts.cs index cd31fd621ca2b..75f0ef998b9da 100644 --- a/src/Compilers/CSharp/Portable/Errors/ErrorFacts.cs +++ b/src/Compilers/CSharp/Portable/Errors/ErrorFacts.cs @@ -411,7 +411,6 @@ internal static int GetWarningLevel(ErrorCode code) case ErrorCode.WRN_CallerLineNumberPreferredOverCallerFilePath: case ErrorCode.WRN_DelaySignButNoKey: case ErrorCode.WRN_UnimplementedCommandLineSwitch: - case ErrorCode.WRN_AsyncLacksAwaits: case ErrorCode.WRN_BadUILang: case ErrorCode.WRN_RefCultureMismatch: case ErrorCode.WRN_ConflictingMachineAssembly: @@ -1485,7 +1484,6 @@ or ErrorCode.ERR_BadAsyncLacksBody or ErrorCode.ERR_BadAwaitInQuery or ErrorCode.ERR_BadAwaitInLock or ErrorCode.ERR_TaskRetNoObjectRequired - or ErrorCode.WRN_AsyncLacksAwaits or ErrorCode.ERR_FileNotFound or ErrorCode.WRN_FileAlreadyIncluded or ErrorCode.ERR_NoFileSpec diff --git a/src/Compilers/CSharp/Portable/FlowAnalysis/DefiniteAssignment.cs b/src/Compilers/CSharp/Portable/FlowAnalysis/DefiniteAssignment.cs index 3eff3de5721b5..4b835ee748f53 100644 --- a/src/Compilers/CSharp/Portable/FlowAnalysis/DefiniteAssignment.cs +++ b/src/Compilers/CSharp/Portable/FlowAnalysis/DefiniteAssignment.cs @@ -403,55 +403,6 @@ protected override ImmutableArray Scan(ref bool badRegion) return pendingReturns; } - protected override ImmutableArray RemoveReturns() - { - var result = base.RemoveReturns(); - - if (CurrentSymbol is MethodSymbol currentMethod && currentMethod.IsAsync && !currentMethod.IsImplicitlyDeclared) - { - var foundAwait = result.Any(static pending => HasAwait(pending)); - if (!foundAwait) - { - // If we're on a LambdaSymbol, then use its 'DiagnosticLocation'. That will be - // much better than using its 'Location' (which is the entire span of the lambda). - var diagnosticLocation = CurrentSymbol is LambdaSymbol lambda - ? lambda.DiagnosticLocation - : CurrentSymbol.GetFirstLocationOrNone(); - - Diagnostics.Add(ErrorCode.WRN_AsyncLacksAwaits, diagnosticLocation); - } - } - - return result; - } - - private static bool HasAwait(PendingBranch pending) - { - var pendingBranch = pending.Branch; - if (pendingBranch is null) - { - return false; - } - - BoundKind kind = pendingBranch.Kind; - switch (kind) - { - case BoundKind.AwaitExpression: - return true; - case BoundKind.UsingStatement: - var usingStatement = (BoundUsingStatement)pendingBranch; - return usingStatement.AwaitOpt != null; - case BoundKind.ForEachStatement: - var foreachStatement = (BoundForEachStatement)pendingBranch; - return foreachStatement.AwaitOpt != null; - case BoundKind.UsingLocalDeclarations: - var localDeclaration = (BoundUsingLocalDeclarations)pendingBranch; - return localDeclaration.AwaitOpt != null; - default: - return false; - } - } - // For purpose of definite assignment analysis, awaits create pending branches, so async usings and foreachs do too public sealed override bool AwaitUsingAndForeachAddsPendingBranch => true; @@ -594,7 +545,7 @@ public static void Analyze( compatDiagnostics.Free(); foreach (var diagnostic in strictDiagnostics.AsEnumerable()) { - // If it is a warning (e.g. WRN_AsyncLacksAwaits), or an error that would be reported by the compatible analysis, just report it. + // If it is a warning, or an error that would be reported by the compatible analysis, just report it. if (diagnostic.Severity != DiagnosticSeverity.Error || compatDiagnosticSet.Contains(diagnostic)) { diagnostics.Add(diagnostic); diff --git a/src/Compilers/CSharp/Portable/Generated/ErrorFacts.Generated.cs b/src/Compilers/CSharp/Portable/Generated/ErrorFacts.Generated.cs index 35a3f0182d26b..34056cc7577b9 100644 --- a/src/Compilers/CSharp/Portable/Generated/ErrorFacts.Generated.cs +++ b/src/Compilers/CSharp/Portable/Generated/ErrorFacts.Generated.cs @@ -116,7 +116,6 @@ public static bool IsWarning(ErrorCode code) case ErrorCode.WRN_MultipleRuntimeOverrideMatches: case ErrorCode.WRN_DynamicDispatchToConditionalMethod: case ErrorCode.WRN_IsDynamicIsConfusing: - case ErrorCode.WRN_AsyncLacksAwaits: case ErrorCode.WRN_FileAlreadyIncluded: case ErrorCode.WRN_NoSources: case ErrorCode.WRN_NoConfigNotOnCommandLine: diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf index 12b1d41ed666c..9c850f22643e7 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf @@ -11125,17 +11125,7 @@ Poskytněte kompilátoru nějaký způsob, jak metody rozlišit. Můžete např Operátor await jde použít jenom ve výrazu dotazu v rámci první kolekce výrazu počáteční klauzule from nebo v rámci výrazu kolekce klauzule join. - - 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. - V této asynchronní metodě chybí operátory await a spustí se synchronně. Zvažte použití operátoru await pro čekání na neblokující volání rozhraní API nebo vykonání činnosti vázané na procesor ve vlákně na pozadí pomocí výrazu await Task.Run(...). - - - - Async method lacks 'await' operators and will run synchronously - V této asynchronní metodě chybí operátory await a spustí se synchronně. - - - + Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call. Protože se toto volání neočekává, vykonávání aktuální metody pokračuje před dokončením volání. Zvažte použití operátoru await na výsledek volání. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf index 33e73c90849ae..71d7f9101a204 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf @@ -11125,17 +11125,7 @@ Unterstützen Sie den Compiler bei der Unterscheidung zwischen den Methoden. Daz Der await-Operator kann in einem Abfrageausdruck nur innerhalb des ersten Sammlungsausdrucks der ursprünglichen from-Klausel oder innerhalb des Sammlungsausdrucks einer join-Klausel verwendet werden. - - 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. - In dieser Async-Methode fehlen die "await"-Operatoren, weshalb sie synchron ausgeführt wird. Sie sollten die Verwendung des "await"-Operators oder von "await Task.Run(...)" in Betracht ziehen, um auf nicht blockierende API-Aufrufe zu warten bzw. CPU-gebundene Aufgaben auf einem Hintergrundthread auszuführen. - - - - Async method lacks 'await' operators and will run synchronously - Bei der asynchronen Methode fehlen "await"-Operatoren. Die Methode wird synchron ausgeführt. - - - + Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call. Da auf diesen Aufruf nicht gewartet wird, wird die Ausführung der aktuellen Methode vor Abschluss des Aufrufs fortgesetzt. Ziehen Sie ein Anwenden des "Await"-Operators auf das Ergebnis des Aufrufs in Betracht. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf index 9ffcdf65762d1..5db9dd0dc9f8c 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf @@ -11125,17 +11125,7 @@ Indique al compilador alguna forma de diferenciar los métodos. Por ejemplo, pue El operador 'await' solo se puede usar en una expresión de consulta dentro de la primera expresión de colección de la cláusula 'from' inicial o de la expresión de colección de una cláusula 'join' - - 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. - El método asincrónico carece de operadores "await" y se ejecutará de forma sincrónica. Puede usar el operador 'await' para esperar llamadas API que no sean de bloqueo o 'await Task.Run(...)' para hacer tareas enlazadas a la CPU en un subproceso en segundo plano. - - - - Async method lacks 'await' operators and will run synchronously - El método asincrónico carece de operadores "await" y se ejecutará de forma sincrónica - - - + Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call. Como esta llamada no es 'awaited', la ejecución del método actual continuará antes de que se complete la llamada. Puede aplicar el operador 'await' al resultado de la llamada. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf index f8d246e2fd9a6..ae96cc2518f8e 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf @@ -11125,17 +11125,7 @@ Permettez au compilateur de différencier les méthodes. Par exemple, vous pouve L'opérateur 'await' peut seulement être utilisé dans une expression de requête dans la première expression de collection de la clause 'from' initiale ou dans l'expression de collection d'une clause 'join' - - 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. - Cette méthode async n'a pas d'opérateur 'await' et elle s'exécutera de façon synchrone. Utilisez l'opérateur 'await' pour attendre les appels d'API non bloquants ou 'await Task.Run(…)' pour effectuer un travail utilisant le processeur sur un thread d'arrière-plan. - - - - Async method lacks 'await' operators and will run synchronously - Cette méthode async n'a pas d'opérateur 'await' et elle s'exécutera de façon synchrone - - - + Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call. Dans la mesure où cet appel n'est pas attendu, l'exécution de la méthode actuelle continue avant la fin de l'appel. Envisagez d'appliquer l'opérateur 'await' au résultat de l'appel. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf index aa84307549eac..6e78268ea250b 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf @@ -11125,17 +11125,7 @@ Impostare il compilatore in modo tale da distinguere i metodi, ad esempio assegn È possibile usare l'operatore 'await' solo in espressioni di query all'interno della prima espressione di raccolta della clausola 'from' iniziale o all'interno dell'espressione di raccolta di una clausola 'join' - - 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. - In questo metodo asincrono non sono presenti operatori 'await', pertanto verrà eseguito in modo sincrono. Provare a usare l'operatore 'await' per attendere chiamate ad API non di blocco oppure 'await Task.Run(...)' per effettuare elaborazioni basate sulla CPU in un thread in background. - - - - Async method lacks 'await' operators and will run synchronously - Il metodo asincrono non contiene operatori 'await', pertanto verrà eseguito in modo sincrono - - - + Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call. Non è possibile attendere la chiamata, pertanto l'esecuzione del metodo corrente continuerà prima del completamento della chiamata. Provare ad applicare l'operatore 'await' al risultato della chiamata. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf index 1957a0a41ab03..a347b60bb32d5 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf @@ -11125,17 +11125,7 @@ C# では out と ref を区別しますが、CLR では同じと認識します await' 演算子は、最初の 'from' 句の最初のコレクション式、または 'join' 句のコレクション式に含まれるクエリ式でのみ使用できます - - 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. - この非同期メソッドには 'await' 演算子がないため、同期的に実行されます。'await' 演算子を使用して非ブロッキング API 呼び出しを待機するか、'await Task.Run(...)' を使用してバックグラウンドのスレッドに対して CPU 主体の処理を実行することを検討してください。 - - - - Async method lacks 'await' operators and will run synchronously - 非同期メソッドは、'await' 演算子がないため、同期的に実行されます - - - + Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call. この呼び出しを待たないため、現在のメソッドの実行は、呼び出しが完了するまで続行します。呼び出しの結果に 'await' 演算子を適用することを検討してください。 diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf index 7e8470f61ca12..4c63f7186ef26 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf @@ -11125,17 +11125,7 @@ C#에서는 out과 ref를 구분하지만 CLR에서는 동일한 것으로 간 await' 연산자는 초기 'from' 절의 첫 번째 Collection 식이나 'join' 절의 Collection 식 내의 쿼리 식에서만 사용할 수 있습니다. - - 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. - 이 비동기 메서드에는 'await' 연산자가 없으며 메서드가 동시에 실행됩니다. 'await' 연산자를 사용하여 비블로킹 API 호출을 대기하거나, 'await Task.Run(...)'을 사용하여 백그라운드 스레드에서 CPU 바인딩된 작업을 수행하세요. - - - - Async method lacks 'await' operators and will run synchronously - 이 비동기 메서드에는 'await' 연산자가 없으며 메서드가 동시에 실행됩니다. - - - + Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call. 이 호출이 대기되지 않으므로 호출이 완료되기 전에 현재 메서드가 계속 실행됩니다. 호출 결과에 'await' 연산자를 적용해 보세요. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf index 67744cdeb7235..acbc21435604b 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf @@ -11125,17 +11125,7 @@ Musisz umożliwić kompilatorowi rozróżnienie metod. Możesz na przykład nada Operatora „await” można użyć tylko w wyrażeniu zapytania w pierwszym wyrażeniu kolekcji początkowej klauzuli „from” albo w wyrażeniu kolekcji klauzuli „join”. - - 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. - W tej metodzie asynchronicznej brakuje operatorów „await”, dlatego będzie wykonywana synchronicznie. Rozważ możliwość użycia operatora „await” w celu zdefiniowania oczekiwania na nieblokujące wywołania interfejsów API albo wyrażenia „await Task.Run(...)” w celu przeniesienia wykonywania zadań intensywnie angażujących procesor do wątku w tle. - - - - Async method lacks 'await' operators and will run synchronously - Metoda asynchroniczna nie zawiera operatorów „await” i zostanie uruchomiona synchronicznie - - - + Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call. Ponieważ to wywołanie nie jest oczekiwane, wykonywanie bieżącej metody będzie kontynuowane bez oczekiwania na ukończenie wywołania. Rozważ możliwość zastosowania operatora „await” do wyniku wywołania. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf index 5b8ccc1307308..a76920c10429b 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf @@ -11125,17 +11125,7 @@ Forneça ao compilador alguma forma de diferenciar os métodos. Por exemplo, voc O operador 'await' só pode ser usado em uma expressão de consulta na primeira expressão de coleção da cláusula 'from' inicial ou na expressão de coleção de uma cláusula 'join' - - 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. - Este método assíncrono não possui operadores 'await' e será executado de modo síncrono. É recomendável o uso do operador 'await' para aguardar chamadas à API desbloqueadas ou do operador 'await Task.Run(...)' para realizar um trabalho associado à CPU em um thread em segundo plano. - - - - Async method lacks 'await' operators and will run synchronously - O método assíncrono não possui operadores 'await' e será executado de forma síncrona - - - + Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call. Como esta chamada não é aguardada, a execução do método atual continua antes da conclusão da chamada. Considere aplicar o operador 'await' ao resultado da chamada. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf index f56eb82ad4048..b823fcf193c1e 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf @@ -11126,17 +11126,7 @@ Give the compiler some way to differentiate the methods. For example, you can gi Оператор await можно использовать только в выражении запроса в первом выражении коллекции начального предложения From или в выражении коллекции предложения Join. - - 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. - В данном асинхронном методе отсутствуют операторы await, поэтому метод будет выполняться синхронно. Воспользуйтесь оператором await для ожидания неблокирующих вызовов API или оператором await Task.Run(...) для выполнения связанных с ЦП заданий в фоновом потоке. - - - - Async method lacks 'await' operators and will run synchronously - В асинхронном методе отсутствуют операторы await, будет выполнен синхронный метод - - - + Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call. Поскольку этот вызов не ожидается, выполнение текущего метода продолжается до завершения вызова. Попробуйте применить оператор await к результату вызова. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf index f3db96e5519af..b31cd0fa52b16 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf @@ -11125,17 +11125,7 @@ Derleyiciye yöntemleri ayrıştırma yolu verin. Örneğin, bunlara farklı adl await' işleci yalnızca başlangıçtaki 'from' yan tümcesinin ilk koleksiyon ifadesinin içindeki ya da bir 'join' yan tümcesinin toplama ifadesinin içindeki bir sorgu ifadesinde kullanılabilir - - 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. - Bu zaman uyumsuz yöntemde 'await' işleçleri yok ve zaman uyumlu çalışacak. 'await' işlecini kullanarak engelleyici olmayan API çağrılarını beklemeyi veya 'await Task.Run(...)' kullanarak bir arka plan iş parçacığında CPU bağlantılı iş yapmayı düşünün. - - - - Async method lacks 'await' operators and will run synchronously - Zaman uyumsuz yöntemde 'await' işleçleri yok ve zaman uyumlu çalışacak - - - + Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call. Bu çağrı beklenmediğinden, çağrı tamamlanmadan geçerli yöntemin yürütülmesi devam eder. Çağrının sonucuna 'await' işlecini eklemeyi düşünün. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf index 028a50115067e..5a9c1affb06d1 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf @@ -11125,17 +11125,7 @@ Give the compiler some way to differentiate the methods. For example, you can gi "await" 运算符只能用在初始 "from" 子句的第一个集合表达式或 "join" 子句的集合表达式内的查询表达式中 - - 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. - 此异步方法缺少 "await" 运算符,将以同步方式运行。请考虑使用 "await" 运算符等待非阻止的 API 调用,或者使用 "await Task.Run(...)" 在后台线程上执行占用大量 CPU 的工作。 - - - - Async method lacks 'await' operators and will run synchronously - 异步方法缺少 "await" 运算符,将以同步方式运行 - - - + Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call. 由于此调用不会等待,因此在此调用完成之前将会继续执行当前方法。请考虑将 "await" 运算符应用于调用结果。 diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf index cda34345fb095..5b004ca8054fc 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf @@ -11125,17 +11125,7 @@ Give the compiler some way to differentiate the methods. For example, you can gi await' 運算子只能用在初始 'from' 子句的第一個集合運算式或 'join' 子句的集合運算式中的查詢運算式 - - 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. - 這個非同步方法缺少 'await' 運算子,因此將以同步方式執行。請考慮使用 'await' 運算子等候未封鎖的應用程式開發介面呼叫,或使用 'await Task.Run(...)' 在背景執行緒上執行 CPU-bound 工作。 - - - - Async method lacks 'await' operators and will run synchronously - Async 方法缺乏 'await' 運算子,將同步執行 - - - + Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call. 因為未等候此呼叫,所以在呼叫完成之前會繼續執行目前的方法。請考慮將 'await' 運算子套用至呼叫的結果。 diff --git a/src/Compilers/CSharp/Test/CommandLine/CommandLineTests.cs b/src/Compilers/CSharp/Test/CommandLine/CommandLineTests.cs index 0b5da55168742..92201963a4ebd 100644 --- a/src/Compilers/CSharp/Test/CommandLine/CommandLineTests.cs +++ b/src/Compilers/CSharp/Test/CommandLine/CommandLineTests.cs @@ -8717,9 +8717,7 @@ public void CS1691WRN_BadWarningNumber_Bug15905() string source = Temp.CreateFile(prefix: "", extension: ".cs").WriteAllText(@" class Program { -#pragma warning disable 1998 public static void Main() { } -#pragma warning restore 1998 } ").Path; var outWriter = new StringWriter(CultureInfo.InvariantCulture); diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncEHTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncEHTests.cs index 3ce646e6931db..979dd03270bed 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncEHTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncEHTests.cs @@ -688,11 +688,7 @@ public static void Main() [G]: Unexpected type on the stack. { Offset = 0x13, Found = Int32, Expected = ref '[System.Runtime]System.Threading.Tasks.Task`1' } """ }); - verifier.VerifyDiagnostics( - // (7,28): 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. - // static async Task F() - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "F").WithLocation(7, 28) - ); + verifier.VerifyDiagnostics(); } [Fact] @@ -739,11 +735,7 @@ public static void Main() [H]: Unexpected type on the stack. { Offset = 0xa, Found = Int32, Expected = ref '[System.Runtime]System.Threading.Tasks.Task`1' } """ }); - verifier.VerifyDiagnostics( - // (7,28): 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. - // static async Task F() - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "F").WithLocation(7, 28) - ); + verifier.VerifyDiagnostics(); } [Fact] @@ -904,11 +896,7 @@ .locals init (int V_0, [G]: Unexpected type on the stack. { Offset = 0x29, Found = Int32, Expected = ref '[System.Runtime]System.Threading.Tasks.Task`1' } """ }); - verifier.VerifyDiagnostics( - // (7,28): 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. - // static async Task F() - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "F").WithLocation(7, 28) - ); + verifier.VerifyDiagnostics(); verifier.VerifyIL("Test.G()", """ { @@ -1008,11 +996,7 @@ public static void Main() [F]: Unexpected type on the stack. { Offset = 0xb, Found = Int32, Expected = ref '[System.Runtime]System.Threading.Tasks.Task`1' } """ }); - verifier.VerifyDiagnostics( - // (7,28): 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. - // static async Task F() - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "F").WithLocation(7, 28) - ); + verifier.VerifyDiagnostics(); verifier.VerifyIL("Test.G()", """ { @@ -1368,11 +1352,7 @@ .locals init (int V_0, [G]: Unexpected type on the stack. { Offset = 0x48, Found = Int32, Expected = ref '[System.Runtime]System.Threading.Tasks.Task`1' } """ }); - verifier.VerifyDiagnostics( - // (7,28): 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. - // static async Task F() - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "F").WithLocation(7, 28) - ); + verifier.VerifyDiagnostics(); verifier.VerifyIL("Test.G()", """ { @@ -1489,11 +1469,7 @@ public static void Main() [G]: Unexpected type on the stack. { Offset = 0x3e, Found = Int32, Expected = ref '[System.Runtime]System.Threading.Tasks.Task`1' } """ }); - verifier.VerifyDiagnostics( - // (7,28): 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. - // static async Task F() - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "F").WithLocation(7, 28) - ); + verifier.VerifyDiagnostics(); verifier.VerifyIL("Test.G()", """ { @@ -1773,11 +1749,7 @@ .locals init (int V_0, [F]: Unexpected type on the stack. { Offset = 0x1, Found = Int32, Expected = ref '[System.Runtime]System.Threading.Tasks.Task`1' } """ }); - verifier.VerifyDiagnostics( - // (6,28): 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. - // static async Task F() - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "F").WithLocation(6, 28) - ); + verifier.VerifyDiagnostics(); verifier.VerifyIL("Test.G()", """ { // Code size 72 (0x48) @@ -2051,11 +2023,7 @@ .locals init (int V_0, [F]: Unexpected type on the stack. { Offset = 0x1, Found = Int32, Expected = ref '[System.Runtime]System.Threading.Tasks.Task`1' } """ }); - verifier.VerifyDiagnostics( - // (6,28): 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. - // static async Task F() - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "F").WithLocation(6, 28) - ); + verifier.VerifyDiagnostics(); verifier.VerifyIL("Test.G(System.Threading.SemaphoreSlim)", """ { // Code size 43 (0x2b) @@ -2304,11 +2272,7 @@ .locals init (int V_0, [F]: Unexpected type on the stack. { Offset = 0x1, Found = Int32, Expected = ref '[System.Runtime]System.Threading.Tasks.Task`1' } """ }); - verifier.VerifyDiagnostics( - // (6,28): 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. - // static async Task F() - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "F").WithLocation(6, 28) - ); + verifier.VerifyDiagnostics(); verifier.VerifyIL("Test.G(System.Threading.SemaphoreSlim)", """ { // Code size 43 (0x2b) @@ -2386,11 +2350,7 @@ public static void Main() [G]: Unexpected type on the stack. { Offset = 0x45, Found = Int32, Expected = ref '[System.Runtime]System.Threading.Tasks.Task`1' } """ }); - verifier.VerifyDiagnostics( - // (5,28): 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. - // static async Task F() - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "F").WithLocation(5, 28) - ); + verifier.VerifyDiagnostics(); verifier.VerifyIL("Test.G()", """ { // Code size 70 (0x46) @@ -2859,11 +2819,7 @@ .locals init (int V_0, [G]: Unexpected type on the stack. { Offset = 0x1f, Found = Int32, Expected = ref '[System.Runtime]System.Threading.Tasks.Task`1' } """ }); - verifier.VerifyDiagnostics( - // (7,28): 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. - // static async Task F() - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "F").WithLocation(7, 28) - ); + verifier.VerifyDiagnostics(); verifier.VerifyIL("Test.G()", """ { @@ -4013,7 +3969,6 @@ class Exception2 : Exception { } public void NestedRethrow_02(bool await1, bool await2, bool await3) { var source = $$""" - #pragma warning disable 1998 // async method lacks 'await' operators using System; using System.Threading.Tasks; diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncIteratorTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncIteratorTests.cs index 435e3bd64c3d0..d745bf90704cf 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncIteratorTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncIteratorTests.cs @@ -1713,9 +1713,6 @@ async System.Collections.Generic.IAsyncEnumerable M2() // (8,9): error CS1622: Cannot return a value from an iterator. Use the yield return statement to return a value, or yield break to end the iteration. // return 1; Diagnostic(ErrorCode.ERR_ReturnInIterator, "return").WithLocation(8, 9), - // (10,60): 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 System.Collections.Generic.IAsyncEnumerable M2() - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "M2").WithLocation(10, 60), // (12,9): error CS1622: Cannot return a value from an iterator. Use the yield return statement to return a value, or yield break to end the iteration. // return 4; Diagnostic(ErrorCode.ERR_ReturnInIterator, "return").WithLocation(12, 9) @@ -1744,9 +1741,6 @@ async System.Collections.Generic.IAsyncEnumerable M2() // (8,9): error CS1622: Cannot return a value from an iterator. Use the yield return statement to return a value, or yield break to end the iteration. // return null; Diagnostic(ErrorCode.ERR_ReturnInIterator, "return").WithLocation(8, 9), - // (10,60): 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 System.Collections.Generic.IAsyncEnumerable M2() - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "M2").WithLocation(10, 60), // (12,9): error CS1622: Cannot return a value from an iterator. Use the yield return statement to return a value, or yield break to end the iteration. // return null; Diagnostic(ErrorCode.ERR_ReturnInIterator, "return").WithLocation(12, 9) @@ -1781,9 +1775,6 @@ async System.Collections.Generic.IAsyncEnumerable M2(ref string s2) // (8,9): error CS1622: Cannot return a value from an iterator. Use the yield return statement to return a value, or yield break to end the iteration. // return ref s; Diagnostic(ErrorCode.ERR_ReturnInIterator, "return").WithLocation(8, 9), - // (10,60): 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 System.Collections.Generic.IAsyncEnumerable M2(ref string s2) - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "M2").WithLocation(10, 60), // (10,74): error CS1988: Async methods cannot have ref, in or out parameters // async System.Collections.Generic.IAsyncEnumerable M2(ref string s2) Diagnostic(ErrorCode.ERR_BadAsyncArgType, "s2").WithLocation(10, 74), @@ -1815,9 +1806,6 @@ async System.Collections.Generic.IAsyncEnumerable M2() // (8,9): error CS1622: Cannot return a value from an iterator. Use the yield return statement to return a value, or yield break to end the iteration. // return default; Diagnostic(ErrorCode.ERR_ReturnInIterator, "return").WithLocation(8, 9), - // (10,60): 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 System.Collections.Generic.IAsyncEnumerable M2() - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "M2").WithLocation(10, 60), // (12,9): error CS1622: Cannot return a value from an iterator. Use the yield return statement to return a value, or yield break to end the iteration. // return default; Diagnostic(ErrorCode.ERR_ReturnInIterator, "return").WithLocation(12, 9) @@ -1943,9 +1931,6 @@ async System.Collections.Generic.IAsyncEnumerator M() }"; var comp = CreateCompilationWithAsyncIterator(source); comp.VerifyDiagnostics( - // (4,60): 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 System.Collections.Generic.IAsyncEnumerator M() - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "M").WithLocation(4, 60), // (6,9): error CS1622: Cannot return a value from an iterator. Use the yield return statement to return a value, or yield break to end the iteration. // return null; Diagnostic(ErrorCode.ERR_ReturnInIterator, "return").WithLocation(6, 9) @@ -2054,15 +2039,8 @@ public static async System.Collections.Generic.IAsyncEnumerable M() } }"; var comp = CreateCompilationWithAsyncIterator(source); - comp.VerifyDiagnostics( - // (4,74): 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. - // public static async System.Collections.Generic.IAsyncEnumerable M() - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "M").WithLocation(4, 74) - ); + comp.VerifyDiagnostics(); comp.VerifyEmitDiagnostics( - // (4,74): 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. - // public static async System.Collections.Generic.IAsyncEnumerable M() - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "M").WithLocation(4, 74), // (4,74): error CS8420: The body of an async-iterator method must contain a 'yield' statement. Consider removing 'async' from the method declaration or adding a 'yield' statement. // public static async System.Collections.Generic.IAsyncEnumerable M() Diagnostic(ErrorCode.ERR_PossibleAsyncIteratorWithoutYieldOrAwait, "M").WithLocation(4, 74) @@ -2086,15 +2064,8 @@ public static async System.Collections.Generic.IAsyncEnumerator M() } }"; var comp = CreateCompilationWithAsyncIterator(source); - comp.VerifyDiagnostics( - // (4,74): 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. - // public static async System.Collections.Generic.IAsyncEnumerator M() - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "M").WithLocation(4, 74) - ); + comp.VerifyDiagnostics(); comp.VerifyEmitDiagnostics( - // (4,74): 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. - // public static async System.Collections.Generic.IAsyncEnumerator M() - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "M").WithLocation(4, 74), // (4,74): error CS8420: The body of an async-iterator method must contain a 'yield' statement. Consider removing `async` from the method declaration. // public static async System.Collections.Generic.IAsyncEnumerator M() Diagnostic(ErrorCode.ERR_PossibleAsyncIteratorWithoutYieldOrAwait, "M").WithLocation(4, 74) @@ -2137,15 +2108,8 @@ async System.Collections.Generic.IAsyncEnumerator M() } }"; var comp = CreateCompilationWithAsyncIterator(source); - comp.VerifyDiagnostics( - // (4,60): 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 System.Collections.Generic.IAsyncEnumerator M() - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "M").WithLocation(4, 60) - ); + comp.VerifyDiagnostics(); comp.VerifyEmitDiagnostics( - // (4,60): 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 System.Collections.Generic.IAsyncEnumerator M() - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "M").WithLocation(4, 60), // (4,60): error CS8420: The body of an async-iterator method must contain a 'yield' statement. Consider removing `async` from the method declaration. // async System.Collections.Generic.IAsyncEnumerator M() Diagnostic(ErrorCode.ERR_PossibleAsyncIteratorWithoutYieldOrAwait, "M").WithLocation(4, 60) @@ -2165,9 +2129,6 @@ public static async System.Collections.Generic.IAsyncEnumerable M() }"; var comp = CreateCompilationWithAsyncIterator(source); comp.VerifyDiagnostics( - // (4,74): 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. - // public static async System.Collections.Generic.IAsyncEnumerable M() - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "M").WithLocation(4, 74), // (4,74): error CS0161: 'C.M()': not all code paths return a value // public static async System.Collections.Generic.IAsyncEnumerable M() Diagnostic(ErrorCode.ERR_ReturnExpected, "M").WithArguments("C.M()").WithLocation(4, 74) @@ -2187,11 +2148,7 @@ public static async System.Collections.Generic.IAsyncEnumerable M() } }"; var comp = CreateCompilationWithAsyncIterator(new[] { Run(iterations: 2), source }, options: TestOptions.DebugExe); - comp.VerifyDiagnostics( - // (4,74): 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. - // public static async System.Collections.Generic.IAsyncEnumerable M() - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "M").WithLocation(4, 74) - ); + comp.VerifyDiagnostics(); CompileAndVerify(comp, expectedOutput: "1 END DISPOSAL DONE"); } @@ -2258,10 +2215,7 @@ static async System.Collections.Generic.IEnumerable M() comp.VerifyDiagnostics( // (4,62): error CS1983: The return type of an async method must be void, Task, Task, a task-like type, IAsyncEnumerable, or IAsyncEnumerator // static async System.Collections.Generic.IEnumerable M() - Diagnostic(ErrorCode.ERR_BadAsyncReturn, "M").WithLocation(4, 62), - // (4,62): 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. - // static async System.Collections.Generic.IEnumerable M() - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "M").WithLocation(4, 62) + Diagnostic(ErrorCode.ERR_BadAsyncReturn, "M").WithLocation(4, 62) ); } @@ -2278,9 +2232,6 @@ public static async System.Collections.Generic.IAsyncEnumerator M() }"; var comp = CreateCompilationWithAsyncIterator(source); comp.VerifyDiagnostics( - // (4,74): 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. - // public static async System.Collections.Generic.IAsyncEnumerable M() - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "M").WithLocation(4, 74), // (4,74): error CS0161: 'C.M()': not all code paths return a value // public static async System.Collections.Generic.IAsyncEnumerable M() Diagnostic(ErrorCode.ERR_ReturnExpected, "M").WithArguments("C.M()").WithLocation(4, 74) @@ -2300,11 +2251,7 @@ static async System.Collections.Generic.IAsyncEnumerator M(int value) } }"; var comp = CreateCompilationWithAsyncIterator(source); - comp.VerifyDiagnostics( - // (4,67): 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. - // static async System.Collections.Generic.IAsyncEnumerator M(int value) - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "M").WithLocation(4, 67) - ); + comp.VerifyDiagnostics(); } [Fact] @@ -6618,11 +6565,7 @@ public static async System.Threading.Tasks.Task Main() } }"; var comp = CreateCompilationWithAsyncIterator(source, options: TestOptions.DebugExe); - comp.VerifyDiagnostics( - // (4,67): 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. - // static async System.Collections.Generic.IAsyncEnumerable M() - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "M").WithLocation(4, 67) - ); + comp.VerifyDiagnostics(); CompileAndVerify(comp, expectedOutput: "1"); } @@ -6646,11 +6589,7 @@ public static async System.Threading.Tasks.Task Main() } }"; var comp = CreateCompilationWithAsyncIterator(source, options: TestOptions.DebugExe); - comp.VerifyDiagnostics( - // (4,67): 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. - // static async System.Collections.Generic.IAsyncEnumerable M() - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "M").WithLocation(4, 67) - ); + comp.VerifyDiagnostics(); CompileAndVerify(comp, expectedOutput: "none"); } @@ -6666,9 +6605,6 @@ async System.Collections.Generic.IAsyncEnumerable M() }"; var comp = CreateCompilationWithAsyncIterator(source); comp.VerifyDiagnostics( - // (4,60): 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 System.Collections.Generic.IAsyncEnumerable M() - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "M").WithLocation(4, 60), // (4,60): error CS0161: 'C.M()': not all code paths return a value // async System.Collections.Generic.IAsyncEnumerable M() Diagnostic(ErrorCode.ERR_ReturnExpected, "M").WithArguments("C.M()").WithLocation(4, 60) @@ -6694,10 +6630,7 @@ async System.Collections.Generic.IAsyncEnumerable M() Diagnostic(ErrorCode.ERR_EmptyYield, "return").WithLocation(7, 15), // (6,22): error CS0029: Cannot implicitly convert type 'string' to 'int' // yield return "hello"; - Diagnostic(ErrorCode.ERR_NoImplicitConv, @"""hello""").WithArguments("string", "int").WithLocation(6, 22), - // (4,60): 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 System.Collections.Generic.IAsyncEnumerable M() - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "M").WithLocation(4, 60) + Diagnostic(ErrorCode.ERR_NoImplicitConv, @"""hello""").WithArguments("string", "int").WithLocation(6, 22) ); } @@ -8895,7 +8828,6 @@ static async System.Threading.Tasks.Task Main() public void LambdaWithBindingErrorInYieldReturn() { var src = """ -#pragma warning disable CS1998 // This async method lacks 'await' operators and will run synchronously using System; using System.Collections.Generic; using System.Threading.Tasks; @@ -8916,7 +8848,6 @@ static async IAsyncEnumerable>> BarAsync() comp.VerifyDiagnostics(); src = """ -#pragma warning disable CS1998 // This async method lacks 'await' operators and will run synchronously using System; using System.Collections.Generic; using System.Threading.Tasks; @@ -8937,21 +8868,22 @@ static async IAsyncEnumerable>> BarAsync() comp = CreateCompilation(src, targetFramework: TargetFramework.Net80); comp.VerifyDiagnostics( - // (12,13): error CS0118: 's' is a variable but is used like a type + // (11,13): error CS0118: 's' is a variable but is used like a type // s // 1 - Diagnostic(ErrorCode.ERR_BadSKknown, "s").WithArguments("s", "variable", "type").WithLocation(12, 13), - // (13,13): error CS4003: 'await' cannot be used as an identifier within an async method or lambda expression + Diagnostic(ErrorCode.ERR_BadSKknown, "s").WithArguments("s", "variable", "type").WithLocation(11, 13), + // (12,13): error CS4003: 'await' cannot be used as an identifier within an async method or lambda expression // await Task.CompletedTask; - Diagnostic(ErrorCode.ERR_BadAwaitAsIdentifier, "await").WithLocation(13, 13), - // (13,13): warning CS0168: The variable 'await' is declared but never used + Diagnostic(ErrorCode.ERR_BadAwaitAsIdentifier, "await").WithLocation(12, 13), + // (12,13): warning CS0168: The variable 'await' is declared but never used // await Task.CompletedTask; - Diagnostic(ErrorCode.WRN_UnreferencedVar, "await").WithArguments("await").WithLocation(13, 13), - // (13,19): error CS1002: ; expected + Diagnostic(ErrorCode.WRN_UnreferencedVar, "await").WithArguments("await").WithLocation(12, 13), + // (12,19): error CS1002: ; expected // await Task.CompletedTask; - Diagnostic(ErrorCode.ERR_SemicolonExpected, "Task").WithLocation(13, 19), - // (13,19): error CS0201: Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement + Diagnostic(ErrorCode.ERR_SemicolonExpected, "Task").WithLocation(12, 19), + // (12,19): error CS0201: Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement // await Task.CompletedTask; - Diagnostic(ErrorCode.ERR_IllegalStatement, "Task.CompletedTask").WithLocation(13, 19)); + Diagnostic(ErrorCode.ERR_IllegalStatement, "Task.CompletedTask").WithLocation(12, 19) + ); var tree = comp.SyntaxTrees.Single(); var model = comp.GetSemanticModel(tree); @@ -8964,7 +8896,6 @@ static async IAsyncEnumerable>> BarAsync() public void LambdaWithBindingErrorInReturn() { var src = """ -#pragma warning disable CS1998 // This async method lacks 'await' operators and will run synchronously using System; using System.Threading.Tasks; @@ -8984,7 +8915,6 @@ static async Task>> BarAsync() comp.VerifyDiagnostics(); src = """ -#pragma warning disable CS1998 // This async method lacks 'await' operators and will run synchronously using System; using System.Threading.Tasks; @@ -9003,21 +8933,22 @@ static async Task>> BarAsync() """; comp = CreateCompilation(src, targetFramework: TargetFramework.Net80); comp.VerifyDiagnostics( - // (11,13): error CS0118: 's' is a variable but is used like a type + // (10,13): error CS0118: 's' is a variable but is used like a type // s // 1 - Diagnostic(ErrorCode.ERR_BadSKknown, "s").WithArguments("s", "variable", "type").WithLocation(11, 13), - // (12,13): error CS4003: 'await' cannot be used as an identifier within an async method or lambda expression + Diagnostic(ErrorCode.ERR_BadSKknown, "s").WithArguments("s", "variable", "type").WithLocation(10, 13), + // (11,13): error CS4003: 'await' cannot be used as an identifier within an async method or lambda expression // await Task.CompletedTask; - Diagnostic(ErrorCode.ERR_BadAwaitAsIdentifier, "await").WithLocation(12, 13), - // (12,13): warning CS0168: The variable 'await' is declared but never used + Diagnostic(ErrorCode.ERR_BadAwaitAsIdentifier, "await").WithLocation(11, 13), + // (11,13): warning CS0168: The variable 'await' is declared but never used // await Task.CompletedTask; - Diagnostic(ErrorCode.WRN_UnreferencedVar, "await").WithArguments("await").WithLocation(12, 13), - // (12,19): error CS1002: ; expected + Diagnostic(ErrorCode.WRN_UnreferencedVar, "await").WithArguments("await").WithLocation(11, 13), + // (11,19): error CS1002: ; expected // await Task.CompletedTask; - Diagnostic(ErrorCode.ERR_SemicolonExpected, "Task").WithLocation(12, 19), - // (12,19): error CS0201: Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement + Diagnostic(ErrorCode.ERR_SemicolonExpected, "Task").WithLocation(11, 19), + // (11,19): error CS0201: Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement // await Task.CompletedTask; - Diagnostic(ErrorCode.ERR_IllegalStatement, "Task.CompletedTask").WithLocation(12, 19)); + Diagnostic(ErrorCode.ERR_IllegalStatement, "Task.CompletedTask").WithLocation(11, 19) + ); var tree = comp.SyntaxTrees.Single(); var model = comp.GetSemanticModel(tree); @@ -10870,9 +10801,7 @@ public void Repro_78640() static class C { - #pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously public static async IAsyncEnumerable AsAsyncEnumerable(this IEnumerable enumerable, [EnumeratorCancellation] CancellationToken cancellationToken) - #pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously { ArgumentNullException.ThrowIfNull(enumerable); diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncMainTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncMainTests.cs index 379636e59b2f5..a13a3dca71467 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncMainTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncMainTests.cs @@ -1271,12 +1271,6 @@ async static Task Main(string[] args) } }"; var compilation = CreateCompilationWithMscorlib461(source, options: TestOptions.ReleaseDebugExe, parseOptions: TestOptions.Regular.WithLanguageVersion(LanguageVersion.CSharp7)).VerifyDiagnostics( - // (6,28): 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 static Task Main() - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "Main").WithLocation(6, 28), - // (12,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 static Task Main(string[] args) - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "Main").WithLocation(12, 30), // (6,18): error CS8107: Feature 'async main' is not available in C# 7. Please use language version 7.1 or greater. // async static Task Main() Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion7, "Task").WithArguments("async main", "7.1").WithLocation(6, 18), diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncSpillTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncSpillTests.cs index bc5f8f01cddba..ca2758c661b01 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncSpillTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncSpillTests.cs @@ -554,7 +554,6 @@ .maxstack 2 public void SpillNestedUnary() { var source = @" -#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously using System; using System.Threading.Tasks; @@ -2029,10 +2028,7 @@ Not Valid! verifier.VerifyDiagnostics( // (23,17): warning CS8073: The result of the expression is always 'true' since a value of type 'Guid' is never equal to 'null' of type 'Guid?' // if (item.Item2 != null || await IsValid(item.Item2)) - Diagnostic(ErrorCode.WRN_NubExprIsConstBool2, "item.Item2 != null").WithArguments("true", "System.Guid", "System.Guid?").WithLocation(23, 17), - // (29,41): 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. - // private static async Task IsValid(Guid id) - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "IsValid").WithLocation(29, 41) + Diagnostic(ErrorCode.WRN_NubExprIsConstBool2, "item.Item2 != null").WithArguments("true", "System.Guid", "System.Guid?").WithLocation(23, 17) ); verifier.VerifyIL("AsyncConditionalBug.Program.DoSomething(System.Tuple)", """ { @@ -4313,7 +4309,6 @@ .locals init (int V_0) public void SpillArrayAssign2() { var source = @" -#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously using System.Threading.Tasks; class Program @@ -8417,9 +8412,6 @@ static async Task Main() }); verifier.VerifyDiagnostics( - // (14,23): 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. - // static async Task Main() - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "Main").WithLocation(14, 23), // (16,9): warning CS4014: Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call. // M(); Diagnostic(ErrorCode.WRN_UnobservedAwaitableExpression, "M()").WithLocation(16, 9) @@ -8511,11 +8503,7 @@ static async Task Main() """ }); - verifier.VerifyDiagnostics( - // (7,16): 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 Task M() - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "M").WithLocation(7, 16) - ); + verifier.VerifyDiagnostics(); verifier.VerifyIL("S.M()", """ { // Code size 16 (0x10) @@ -8583,11 +8571,7 @@ public async Task M() """ }); - verifier.VerifyDiagnostics( - // (26,27): 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. - // public async Task M() - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "M").WithLocation(26, 27) - ); + verifier.VerifyDiagnostics(); verifier.VerifyIL("Extensions.M(this T)", """ { // Code size 15 (0xf) @@ -8642,10 +8626,7 @@ public async Task M() var expectedDiagnostics = new[] { // (26,27): error CS1988: Async methods cannot have ref, in or out parameters // public async Task M() - Diagnostic(ErrorCode.ERR_BadAsyncArgType, "M").WithLocation(26, 27), - // (26,27): 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. - // public async Task M() - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "M").WithLocation(26, 27) + Diagnostic(ErrorCode.ERR_BadAsyncArgType, "M").WithLocation(26, 27) }; var comp = CreateCompilation(source, parseOptions: TestOptions.Regular14); @@ -8699,10 +8680,7 @@ public async Task M() Diagnostic(ErrorCode.ERR_RefExtensionParameterMustBeValueTypeOrConstrainedToOne, "T").WithLocation(24, 22), // (26,27): error CS1988: Async methods cannot have ref, in or out parameters // public async Task M() - Diagnostic(ErrorCode.ERR_BadAsyncArgType, "M").WithLocation(26, 27), - // (26,27): 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. - // public async Task M() - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "M").WithLocation(26, 27) + Diagnostic(ErrorCode.ERR_BadAsyncArgType, "M").WithLocation(26, 27) }; var comp = CreateCompilation(source, parseOptions: TestOptions.Regular14); diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncTests.cs index aae7c293df18c..b1ef2381ff792 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncTests.cs @@ -373,11 +373,7 @@ public static async Task Main() {ReturnValueMissing("g__Impl|1_0", "0x7")} """ }, symbolValidator: verify); - verifier.VerifyDiagnostics( - // (13,25): 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 ValueTask Impl() - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "Impl").WithLocation(13, 25) - ); + verifier.VerifyDiagnostics(); verifier.VerifyIL("Test.F", """ { @@ -2111,7 +2107,6 @@ public void AddressOf_Fixed() var source = """ using System.Threading.Tasks; // 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. - #pragma warning disable 1998 class Program { int F; @@ -2150,41 +2145,41 @@ struct S { public int F; } """; CreateCompilation(source, options: TestOptions.UnsafeDebugExe).VerifyDiagnostics( - // (11,20): error CS0212: You can only take the address of an unfixed expression inside of a fixed statement initializer + // (10,20): error CS0212: You can only take the address of an unfixed expression inside of a fixed statement initializer // int* ptr = &prog.F; // 1 - Diagnostic(ErrorCode.ERR_FixedNeeded, "&prog.F").WithLocation(11, 20), - // (15,26): warning CS9123: The '&' operator should not be used on parameters or local variables in async methods. + Diagnostic(ErrorCode.ERR_FixedNeeded, "&prog.F").WithLocation(10, 20), + // (14,26): warning CS9123: The '&' operator should not be used on parameters or local variables in async methods. // int* localPtr = &local; // 2 - Diagnostic(ErrorCode.WRN_AddressOfInAsync, "local").WithLocation(15, 26), - // (16,33): error CS0213: You cannot use the fixed statement to take the address of an already fixed expression + Diagnostic(ErrorCode.WRN_AddressOfInAsync, "local").WithLocation(14, 26), + // (15,33): error CS0213: You cannot use the fixed statement to take the address of an already fixed expression // fixed (int* localPtr1 = &local) { } // 3, 4 - Diagnostic(ErrorCode.ERR_FixedNotNeeded, "&local").WithLocation(16, 33), - // (16,34): warning CS9123: The '&' operator should not be used on parameters or local variables in async methods. + Diagnostic(ErrorCode.ERR_FixedNotNeeded, "&local").WithLocation(15, 33), + // (15,34): warning CS9123: The '&' operator should not be used on parameters or local variables in async methods. // fixed (int* localPtr1 = &local) { } // 3, 4 - Diagnostic(ErrorCode.WRN_AddressOfInAsync, "local").WithLocation(16, 34), - // (19,26): warning CS9123: The '&' operator should not be used on parameters or local variables in async methods. + Diagnostic(ErrorCode.WRN_AddressOfInAsync, "local").WithLocation(15, 34), + // (18,26): warning CS9123: The '&' operator should not be used on parameters or local variables in async methods. // int* innerPtr = &structLocal.F; // 5 - Diagnostic(ErrorCode.WRN_AddressOfInAsync, "structLocal.F").WithLocation(19, 26), - // (20,33): error CS0213: You cannot use the fixed statement to take the address of an already fixed expression + Diagnostic(ErrorCode.WRN_AddressOfInAsync, "structLocal.F").WithLocation(18, 26), + // (19,33): error CS0213: You cannot use the fixed statement to take the address of an already fixed expression // fixed (int* innerPtr1 = &structLocal.F) { } // 6, 7 - Diagnostic(ErrorCode.ERR_FixedNotNeeded, "&structLocal.F").WithLocation(20, 33), - // (20,34): warning CS9123: The '&' operator should not be used on parameters or local variables in async methods. + Diagnostic(ErrorCode.ERR_FixedNotNeeded, "&structLocal.F").WithLocation(19, 33), + // (19,34): warning CS9123: The '&' operator should not be used on parameters or local variables in async methods. // fixed (int* innerPtr1 = &structLocal.F) { } // 6, 7 - Diagnostic(ErrorCode.WRN_AddressOfInAsync, "structLocal.F").WithLocation(20, 34), - // (33,39): warning CS9123: The '&' operator should not be used on parameters or local variables in async methods. + Diagnostic(ErrorCode.WRN_AddressOfInAsync, "structLocal.F").WithLocation(19, 34), + // (32,39): warning CS9123: The '&' operator should not be used on parameters or local variables in async methods. // int* localFuncLocalPtr = &localFuncLocal; // 8 - Diagnostic(ErrorCode.WRN_AddressOfInAsync, "localFuncLocal").WithLocation(33, 39)); + Diagnostic(ErrorCode.WRN_AddressOfInAsync, "localFuncLocal").WithLocation(32, 39)); CreateCompilation(source, options: TestOptions.UnsafeDebugExe.WithWarningLevel(7)).VerifyDiagnostics( - // (11,20): error CS0212: You can only take the address of an unfixed expression inside of a fixed statement initializer + // (10,20): error CS0212: You can only take the address of an unfixed expression inside of a fixed statement initializer // int* ptr = &prog.F; // 1 - Diagnostic(ErrorCode.ERR_FixedNeeded, "&prog.F").WithLocation(11, 20), - // (16,33): error CS0213: You cannot use the fixed statement to take the address of an already fixed expression + Diagnostic(ErrorCode.ERR_FixedNeeded, "&prog.F").WithLocation(10, 20), + // (15,33): error CS0213: You cannot use the fixed statement to take the address of an already fixed expression // fixed (int* localPtr1 = &local) { } // 3, 4 - Diagnostic(ErrorCode.ERR_FixedNotNeeded, "&local").WithLocation(16, 33), - // (20,33): error CS0213: You cannot use the fixed statement to take the address of an already fixed expression + Diagnostic(ErrorCode.ERR_FixedNotNeeded, "&local").WithLocation(15, 33), + // (19,33): error CS0213: You cannot use the fixed statement to take the address of an already fixed expression // fixed (int* innerPtr1 = &structLocal.F) { } // 6, 7 - Diagnostic(ErrorCode.ERR_FixedNotNeeded, "&structLocal.F").WithLocation(20, 33)); + Diagnostic(ErrorCode.ERR_FixedNotNeeded, "&structLocal.F").WithLocation(19, 33)); } [Fact] @@ -4905,9 +4900,6 @@ async void M() {} // CONSIDER: It would be nice if we didn't squiggle the whole method body, but this is a corner case. comp.VerifyEmitDiagnostics( - // (4,16): 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 void M() {} - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "M").WithLocation(4, 16), // (4,20): error CS0518: Predefined type 'System.Runtime.CompilerServices.AsyncVoidMethodBuilder' is not defined or imported // async void M() {} Diagnostic(ErrorCode.ERR_PredefinedTypeNotFound, "{}").WithArguments("System.Runtime.CompilerServices.AsyncVoidMethodBuilder").WithLocation(4, 20), @@ -4933,9 +4925,6 @@ async Task M() {} }"; var comp = CSharpTestBase.CreateEmptyCompilation(source, new[] { Net40.References.mscorlib }, TestOptions.ReleaseDll); // NOTE: 4.0, not 4.5, so it's missing the async helpers. comp.VerifyEmitDiagnostics( - // (4,16): 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 Task M() {} - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "M").WithLocation(4, 16), // (4,20): error CS0518: Predefined type 'System.Runtime.CompilerServices.AsyncTaskMethodBuilder' is not defined or imported // async Task M() {} Diagnostic(ErrorCode.ERR_PredefinedTypeNotFound, "{}").WithArguments("System.Runtime.CompilerServices.AsyncTaskMethodBuilder").WithLocation(4, 20), @@ -4964,9 +4953,6 @@ class C }"; var comp = CSharpTestBase.CreateEmptyCompilation(source, new[] { Net40.References.mscorlib }, TestOptions.ReleaseDll); // NOTE: 4.0, not 4.5, so it's missing the async helpers. comp.VerifyEmitDiagnostics( - // (4,21): 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 Task F() => 3; - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "F").WithLocation(4, 21), // (4,25): error CS0518: Predefined type 'System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1' is not defined or imported // async Task F() => 3; Diagnostic(ErrorCode.ERR_PredefinedTypeNotFound, "=> 3").WithArguments("System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1").WithLocation(4, 25), @@ -7521,15 +7507,8 @@ private static ref long ReadMemory() } } "; - var diags = new[] - { - // (12,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. - // public static async Task CompletedTask() - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "CompletedTask").WithLocation(12, 30) - }; - - CompileAndVerify(source, options: TestOptions.DebugExe, verify: Verification.Skipped, expectedOutput: "0123").VerifyDiagnostics(diags); - CompileAndVerify(source, options: TestOptions.ReleaseExe, verify: Verification.Skipped, expectedOutput: "0123").VerifyDiagnostics(diags); + CompileAndVerify(source, options: TestOptions.DebugExe, verify: Verification.Skipped, expectedOutput: "0123").VerifyDiagnostics(); + CompileAndVerify(source, options: TestOptions.ReleaseExe, verify: Verification.Skipped, expectedOutput: "0123").VerifyDiagnostics(); } [Fact, WorkItem(40251, "https://github.com/dotnet/roslyn/issues/40251")] @@ -9205,7 +9184,6 @@ public static async Task Handler() } } - #pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously public static async Task Throw(int value) => throw new IntegerException(value); } @@ -9312,7 +9290,6 @@ public static Task Handler() } } - #pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously public static async Task Throw(int value) => throw new IntegerException(value); } @@ -9665,9 +9642,6 @@ public static void M4() // (18,6): error CS9330: 'MethodImplAttribute.Async' cannot be manually applied to methods. Mark the method 'async'. // [MethodImpl(MethodImplOptions.Async)] Diagnostic(ErrorCode.ERR_MethodImplAttributeAsyncCannotBeUsed, "MethodImpl(MethodImplOptions.Async)").WithLocation(18, 6), - // (19,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. - // public static async Task M3() - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "M3").WithLocation(19, 30), // (24,6): error CS9330: 'MethodImplAttribute.Async' cannot be manually applied to methods. Mark the method 'async'. // [MethodImpl(MethodImplOptions.Async | MethodImplOptions.Synchronized)] Diagnostic(ErrorCode.ERR_MethodImplAttributeAsyncCannotBeUsed, "MethodImpl(MethodImplOptions.Async | MethodImplOptions.Synchronized)").WithLocation(24, 6) diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAwaitUsingTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAwaitUsingTests.cs index 0ffcbdbf53424..b47a482494db6 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAwaitUsingTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAwaitUsingTests.cs @@ -172,10 +172,7 @@ public async Task DisposeAsync() { } comp.VerifyDiagnostics( // (3,11): error CS0738: 'C' does not implement interface member 'IAsyncDisposable.DisposeAsync()'. 'C.DisposeAsync()' cannot implement 'IAsyncDisposable.DisposeAsync()' because it does not have the matching return type of 'ValueTask'. // class C : System.IAsyncDisposable - Diagnostic(ErrorCode.ERR_CloseUnimplementedInterfaceMemberWrongReturnType, "System.IAsyncDisposable").WithArguments("C", "System.IAsyncDisposable.DisposeAsync()", "C.DisposeAsync()", "System.Threading.Tasks.ValueTask").WithLocation(3, 11), - // (9,23): 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. - // public async Task DisposeAsync() { } - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "DisposeAsync").WithLocation(9, 23) + Diagnostic(ErrorCode.ERR_CloseUnimplementedInterfaceMemberWrongReturnType, "System.IAsyncDisposable").WithArguments("C", "System.IAsyncDisposable.DisposeAsync()", "C.DisposeAsync()", "System.Threading.Tasks.ValueTask").WithLocation(3, 11) ); } @@ -555,11 +552,7 @@ async System.Threading.Tasks.Task local() } "; var comp = CreateCompilationWithTasksExtensions(new[] { source, IAsyncDisposableDefinition }); - comp.VerifyDiagnostics( - // (4,53): 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. - // public static async System.Threading.Tasks.Task Main() - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "Main").WithLocation(4, 53) - ); + comp.VerifyDiagnostics(); } [Fact] @@ -598,14 +591,7 @@ async System.Threading.Tasks.Task innerLocal() } "; var comp = CreateCompilationWithTasksExtensions(new[] { source, IAsyncDisposableDefinition }); - comp.VerifyDiagnostics( - // (17,43): 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 System.Threading.Tasks.Task local() - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "local").WithLocation(17, 43), - // (6,42): 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. - // System.Action lambda1 = async () => - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "=>").WithLocation(6, 42) - ); + comp.VerifyDiagnostics(); } [Fact] diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenFunctionPointersTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenFunctionPointersTests.cs index a86ab7c342676..7b9691dbc384c 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenFunctionPointersTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenFunctionPointersTests.cs @@ -6458,8 +6458,7 @@ protected override void M7(delegate* ptr) {} protected override delegate* M8() => throw null; }"); - comp.VerifyDiagnostics( - ); + comp.VerifyDiagnostics(); assertMethods(comp.SourceModule); CompileAndVerify(comp, symbolValidator: assertMethods); @@ -6511,8 +6510,7 @@ protected override void M7(delegate* ptr) {} protected override delegate* M8() => throw null; }"); - comp.VerifyDiagnostics( - ); + comp.VerifyDiagnostics(); assertMethods(comp.SourceModule); CompileAndVerify(comp, symbolValidator: assertMethods, verify: Verification.Skipped); @@ -9799,18 +9797,12 @@ public static async Task Main() {} // (6,30): error CS0017: Program has more than one entry point defined. Compile with /main to specify the type that contains the entry point. // public static async Task Main() {} Diagnostic(ErrorCode.ERR_MultipleEntryPoints, "Main").WithLocation(6, 30), - // (6,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. - // public static async Task Main() {} - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "Main").WithLocation(6, 30), // (11,25): error CS8894: Cannot use 'Task' as a return type on a method attributed with 'UnmanagedCallersOnly'. // public static async Task Main() {} Diagnostic(ErrorCode.ERR_CannotUseManagedTypeInUnmanagedCallersOnly, "Task").WithArguments("System.Threading.Tasks.Task", "return").WithLocation(11, 25), // (11,30): error CS8899: Application entry points cannot be attributed with 'UnmanagedCallersOnly'. // public static async Task Main() {} - Diagnostic(ErrorCode.ERR_EntryPointCannotBeUnmanagedCallersOnly, "Main").WithLocation(11, 30), - // (11,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. - // public static async Task Main() {} - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "Main").WithLocation(11, 30) + Diagnostic(ErrorCode.ERR_EntryPointCannotBeUnmanagedCallersOnly, "Main").WithLocation(11, 30) ); } @@ -9837,10 +9829,7 @@ public static async Task Main() {} Diagnostic(ErrorCode.ERR_CannotUseManagedTypeInUnmanagedCallersOnly, "Task").WithArguments("System.Threading.Tasks.Task", "return").WithLocation(11, 25), // (11,30): warning CS8892: Method 'D.Main()' will not be used as an entry point because a synchronous entry point 'C.Main()' was found. // public static async Task Main() {} - Diagnostic(ErrorCode.WRN_SyncAndAsyncEntryPoints, "Main").WithArguments("D.Main()", "C.Main()").WithLocation(11, 30), - // (11,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. - // public static async Task Main() {} - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "Main").WithLocation(11, 30) + Diagnostic(ErrorCode.WRN_SyncAndAsyncEntryPoints, "Main").WithArguments("D.Main()", "C.Main()").WithLocation(11, 30) ); } diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenShortCircuitOperatorTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenShortCircuitOperatorTests.cs index f3538e88440e6..0c33fb356fbee 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenShortCircuitOperatorTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenShortCircuitOperatorTests.cs @@ -5817,7 +5817,6 @@ public T M() public void ConditionalInAsyncTask() { var source = @" -#pragma warning disable CS1998 // suppress 'no await in async' warning using System; using System.Threading.Tasks; diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTryFinally.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTryFinally.cs index 1dc1c2eaf6375..74e8d38756876 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTryFinally.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTryFinally.cs @@ -4276,9 +4276,6 @@ async Task M() var expectedDiagnostics = new[] { - // (6,16): 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 Task M() - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "M").WithLocation(6, 16), // (10,9): warning CS0162: Unreachable code detected // try Diagnostic(ErrorCode.WRN_UnreachableCode, "try").WithLocation(10, 9) @@ -4311,11 +4308,7 @@ async Task M() } """; - CompileAndVerify(source, options: TestOptions.ReleaseDll).VerifyDiagnostics( - // (6,16): 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 Task M() - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "M").WithLocation(6, 16) - ); + CompileAndVerify(source, options: TestOptions.ReleaseDll).VerifyDiagnostics(); } } } diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/PatternTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/PatternTests.cs index 86e1ed704dbc7..74ae46d3796a4 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/PatternTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/PatternTests.cs @@ -4540,10 +4540,7 @@ static async Task Main() "; var expectedOutput = "correct"; var compilation = CreateCompilation(source, options: TestOptions.ReleaseExe); - compilation.VerifyDiagnostics( - // (7,23): 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. - // static async Task Main() - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "Main").WithLocation(7, 23)); + compilation.VerifyDiagnostics(); var compVerifier = CompileAndVerify(compilation, expectedOutput: expectedOutput); } @@ -4574,10 +4571,7 @@ static async Task Main() "; var expectedOutput = "correct"; var compilation = CreateCompilation(source, options: TestOptions.ReleaseExe); - compilation.VerifyDiagnostics( - // (7,23): 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. - // static async Task Main() - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "Main").WithLocation(7, 23)); + compilation.VerifyDiagnostics(); var compVerifier = CompileAndVerify(compilation, expectedOutput: expectedOutput); } diff --git a/src/Compilers/CSharp/Test/Emit3/RefStructInterfacesTests.cs b/src/Compilers/CSharp/Test/Emit3/RefStructInterfacesTests.cs index efa0af3603fdd..476539e71fd1f 100644 --- a/src/Compilers/CSharp/Test/Emit3/RefStructInterfacesTests.cs +++ b/src/Compilers/CSharp/Test/Emit3/RefStructInterfacesTests.cs @@ -22471,8 +22471,6 @@ public class Unsafe public void AsyncParameter() { var src = @" -#pragma warning disable CS1998 // This async method lacks 'await' operators and will run synchronously. - public class Helper { static async void Test1(T x) @@ -22492,12 +22490,12 @@ ref struct S var comp = CreateCompilation(src, targetFramework: s_targetFrameworkSupportingByRefLikeGenerics); comp.VerifyDiagnostics( - // (6,34): error CS4012: Parameters of type 'T' cannot be declared in async methods or async lambda expressions. + // (4,34): error CS4012: Parameters of type 'T' cannot be declared in async methods or async lambda expressions. // static async void Test1(T x) - Diagnostic(ErrorCode.ERR_BadSpecialByRefParameter, "x").WithArguments("T").WithLocation(6, 34), - // (11,31): error CS4012: Parameters of type 'S' cannot be declared in async methods or async lambda expressions. + Diagnostic(ErrorCode.ERR_BadSpecialByRefParameter, "x").WithArguments("T").WithLocation(4, 34), + // (9,31): error CS4012: Parameters of type 'S' cannot be declared in async methods or async lambda expressions. // static async void Test2(S y) - Diagnostic(ErrorCode.ERR_BadSpecialByRefParameter, "y").WithArguments("S").WithLocation(11, 31) + Diagnostic(ErrorCode.ERR_BadSpecialByRefParameter, "y").WithArguments("S").WithLocation(9, 31) ); } @@ -29516,8 +29514,6 @@ public void Iterator_04() { var source = @" -#pragma warning disable CS1998 // This async method lacks 'await' operators - using System.Collections.Generic; static class CSharpCompilerCrash @@ -29533,9 +29529,9 @@ static async IAsyncEnumerable B() "; var comp = CreateCompilation(source, targetFramework: TargetFramework.Net90); comp.VerifyDiagnostics( - // (8,47): error CS9266: Element type of an iterator may not be a ref struct or a type parameter allowing ref structs + // (6,47): error CS9266: Element type of an iterator may not be a ref struct or a type parameter allowing ref structs // static async IAsyncEnumerable B() - Diagnostic(ErrorCode.ERR_IteratorRefLikeElementType, "B").WithLocation(8, 47) + Diagnostic(ErrorCode.ERR_IteratorRefLikeElementType, "B").WithLocation(6, 47) ); } @@ -29546,8 +29542,6 @@ public void Iterator_05() { var source = @" -#pragma warning disable CS1998 // This async method lacks 'await' operators - using System.Collections.Generic; static class CSharpCompilerCrash @@ -29563,9 +29557,9 @@ static async IAsyncEnumerator B() "; var comp = CreateCompilation(source, targetFramework: TargetFramework.Net90); comp.VerifyDiagnostics( - // (8,47): error CS9266: Element type of an iterator may not be a ref struct or a type parameter allowing ref structs + // (6,47): error CS9266: Element type of an iterator may not be a ref struct or a type parameter allowing ref structs // static async IAsyncEnumerator B() - Diagnostic(ErrorCode.ERR_IteratorRefLikeElementType, "B").WithLocation(8, 47) + Diagnostic(ErrorCode.ERR_IteratorRefLikeElementType, "B").WithLocation(6, 47) ); } @@ -29576,8 +29570,6 @@ public void Iterator_06() { var source = @" -#pragma warning disable CS1998 // This async method lacks 'await' operators - using System.Collections.Generic; static class CSharpCompilerCrash @@ -29591,9 +29583,9 @@ static async IAsyncEnumerator B() where T : allows ref struct "; var comp = CreateCompilation(source, targetFramework: TargetFramework.Net90); comp.VerifyDiagnostics( - // (8,38): error CS9266: Element type of an iterator may not be a ref struct or a type parameter allowing ref structs + // (6,38): error CS9266: Element type of an iterator may not be a ref struct or a type parameter allowing ref structs // static async IAsyncEnumerator B() where T : allows ref struct - Diagnostic(ErrorCode.ERR_IteratorRefLikeElementType, "B").WithLocation(8, 38) + Diagnostic(ErrorCode.ERR_IteratorRefLikeElementType, "B").WithLocation(6, 38) ); } diff --git a/src/Compilers/CSharp/Test/Emit3/Semantics/ExtensionTests.cs b/src/Compilers/CSharp/Test/Emit3/Semantics/ExtensionTests.cs index 9507fd98555d3..f87d4fb1681ba 100644 --- a/src/Compilers/CSharp/Test/Emit3/Semantics/ExtensionTests.cs +++ b/src/Compilers/CSharp/Test/Emit3/Semantics/ExtensionTests.cs @@ -41865,13 +41865,8 @@ unsafe static class E comp.VerifyEmitDiagnostics( // (3,15): error CS1103: The receiver parameter of an extension cannot be of type 'int*' // extension(int* i) - Diagnostic(ErrorCode.ERR_BadTypeforThis, "int*").WithArguments("int*").WithLocation(3, 15), - // (5,34): 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. - // public static async void M() => throw null; - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "M").WithLocation(5, 34), - // (6,27): 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. - // public async void M2() => throw null; - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "M2").WithLocation(6, 27)); + Diagnostic(ErrorCode.ERR_BadTypeforThis, "int*").WithArguments("int*").WithLocation(3, 15) + ); } [Fact] diff --git a/src/Compilers/CSharp/Test/Emit3/Semantics/ExtensionTests2.cs b/src/Compilers/CSharp/Test/Emit3/Semantics/ExtensionTests2.cs index 4f7a84d35e189..8a49e66f9e6d2 100644 --- a/src/Compilers/CSharp/Test/Emit3/Semantics/ExtensionTests2.cs +++ b/src/Compilers/CSharp/Test/Emit3/Semantics/ExtensionTests2.cs @@ -7582,8 +7582,6 @@ class Program class Program { -// https://github.com/dotnet/roslyn/issues/79416 - remove the pragma once fixed -#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously static async Task Main() { Program.F = new S1 { F1 = 123 }; @@ -7925,8 +7923,6 @@ class Program class Program { -// https://github.com/dotnet/roslyn/issues/79416 - remove the pragma once fixed -#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously static async Task Main() { Program.F = new C1 { F1 = 123 }; @@ -17103,8 +17099,6 @@ class Program class Program { -// https://github.com/dotnet/roslyn/issues/79416 - remove the pragma once fixed -#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously static async Task Main() { Program.F = new S1 { F1 = 123 }; @@ -17534,8 +17528,6 @@ class Program class Program { -// https://github.com/dotnet/roslyn/issues/79416 - remove the pragma once fixed -#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously static async Task Main() { Program.F = new C1 { F1 = 123 }; @@ -18344,8 +18336,6 @@ class Program class Program { -// https://github.com/dotnet/roslyn/issues/79416 - remove the pragma once fixed -#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously static async Task Main() { Program.F = new S1 { F1 = 123 }; @@ -18702,8 +18692,6 @@ class Program class Program { -// https://github.com/dotnet/roslyn/issues/79416 - remove the pragma once fixed -#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously static async Task Main() { Program.F = new C1 { F1 = 123 }; @@ -20126,8 +20114,6 @@ class Program class Program { -// https://github.com/dotnet/roslyn/issues/79416 - remove the pragma once fixed -#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously static async Task Main() { Program.F = new S1 { F1 = 123 }; @@ -20480,8 +20466,6 @@ class Program class Program { -// https://github.com/dotnet/roslyn/issues/79416 - remove the pragma once fixed -#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously static async Task Main() { Program.F = new C1 { F1 = 123 }; @@ -21108,8 +21092,6 @@ class Program class Program { -// https://github.com/dotnet/roslyn/issues/79416 - remove the pragma once fixed -#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously static async Task Main() { Program.F = new S1 { F1 = 123 }; @@ -21391,8 +21373,6 @@ class Program class Program { -// https://github.com/dotnet/roslyn/issues/79416 - remove the pragma once fixed -#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously static async Task Main() { Program.F = new C1 { F1 = 123 }; diff --git a/src/Compilers/CSharp/Test/Emit3/Semantics/LockTests.cs b/src/Compilers/CSharp/Test/Emit3/Semantics/LockTests.cs index 192bbd51c8fae..570e26e36d8f1 100644 --- a/src/Compilers/CSharp/Test/Emit3/Semantics/LockTests.cs +++ b/src/Compilers/CSharp/Test/Emit3/Semantics/LockTests.cs @@ -1926,7 +1926,6 @@ public void Await() public void AsyncMethod() { var source = """ - #pragma warning disable 1998 // async method lacks 'await' operators using System.Threading; using System.Threading.Tasks; @@ -2373,7 +2372,6 @@ .locals init (int V_0, public void AsyncMethod_AwaitResource() { var source = """ - #pragma warning disable 1998 // async method lacks 'await' operators using System.Threading; using System.Threading.Tasks; @@ -2597,7 +2595,6 @@ .locals init (int V_0, public void AsyncLocalFunction() { var source = """ - #pragma warning disable 1998 // async method lacks 'await' operators using System.Threading; async void local() @@ -3041,7 +3038,6 @@ .locals init (int V_0, public void AsyncLambda() { var source = """ - #pragma warning disable 1998 // async method lacks 'await' operators using System.Threading; var lam = async () => diff --git a/src/Compilers/CSharp/Test/Emit3/Semantics/OutVarTests.cs b/src/Compilers/CSharp/Test/Emit3/Semantics/OutVarTests.cs index 36a1708cfa72a..544d66386b6b8 100644 --- a/src/Compilers/CSharp/Test/Emit3/Semantics/OutVarTests.cs +++ b/src/Compilers/CSharp/Test/Emit3/Semantics/OutVarTests.cs @@ -652,8 +652,7 @@ static object Test1(out int x) }"; var compilation = CreateCompilation(text, options: TestOptions.ReleaseExe, parseOptions: TestOptions.Regular); - compilation.VerifyDiagnostics( - ); + compilation.VerifyDiagnostics(); CompileAndVerify(compilation, expectedOutput: "123"); Assert.False(compilation.SyntaxTrees.Single().GetRoot().DescendantNodes().OfType().Any()); @@ -769,8 +768,7 @@ static object Test1(out int x) }"; var compilation = CreateCompilation(text, options: TestOptions.ReleaseExe, parseOptions: TestOptions.Regular); - compilation.VerifyDiagnostics( - ); + compilation.VerifyDiagnostics(); CompileAndVerify(compilation, expectedOutput: "123"); Assert.False(compilation.SyntaxTrees.Single().GetRoot().DescendantNodes().OfType().Any()); @@ -19580,11 +19578,8 @@ static void Test2(object x, System.ArgIterator y) compilation.VerifyDiagnostics( // (11,25): error CS1601: Cannot make reference to variable of type 'ArgIterator' // static object Test1(out System.ArgIterator x) - Diagnostic(ErrorCode.ERR_MethodArgCantBeRefAny, "out System.ArgIterator x").WithArguments("System.ArgIterator").WithLocation(11, 25), - // (6,16): 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 void Test() - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "Test").WithLocation(6, 16) - ); + Diagnostic(ErrorCode.ERR_MethodArgCantBeRefAny, "out System.ArgIterator x").WithArguments("System.ArgIterator").WithLocation(11, 25) + ); var tree = compilation.SyntaxTrees.Single(); var model = compilation.GetSemanticModel(tree); @@ -19635,11 +19630,8 @@ static void Test2(object x, System.ArgIterator y) Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion12, "var").WithArguments("ref and unsafe in async and iterator methods", "13.0").WithLocation(9, 9), // (9,13): warning CS0219: The variable 'x' is assigned but its value is never used // var x = default(System.ArgIterator); - Diagnostic(ErrorCode.WRN_UnreferencedVarAssg, "x").WithArguments("x").WithLocation(9, 13), - // (6,16): 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 void Test() - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "Test").WithLocation(6, 16) - ); + Diagnostic(ErrorCode.WRN_UnreferencedVarAssg, "x").WithArguments("x").WithLocation(9, 13) + ); compilation = CreateCompilation(text, targetFramework: TargetFramework.Mscorlib461); @@ -19649,11 +19641,8 @@ static void Test2(object x, System.ArgIterator y) Diagnostic(ErrorCode.ERR_MethodArgCantBeRefAny, "out System.ArgIterator x").WithArguments("System.ArgIterator").WithLocation(12, 25), // (9,13): warning CS0219: The variable 'x' is assigned but its value is never used // var x = default(System.ArgIterator); - Diagnostic(ErrorCode.WRN_UnreferencedVarAssg, "x").WithArguments("x").WithLocation(9, 13), - // (6,16): 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 void Test() - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "Test").WithLocation(6, 16) - ); + Diagnostic(ErrorCode.WRN_UnreferencedVarAssg, "x").WithArguments("x").WithLocation(9, 13) + ); var tree = compilation.SyntaxTrees.Single(); var model = compilation.GetSemanticModel(tree); @@ -35732,8 +35721,7 @@ static void DumpArgs(ArgIterator args) }"; var compilation = CreateCompilation(text, options: TestOptions.ReleaseExe, parseOptions: TestOptions.Regular); - compilation.VerifyDiagnostics( - ); + compilation.VerifyDiagnostics(); CompileAndVerify(compilation, expectedOutput: "23True"); } diff --git a/src/Compilers/CSharp/Test/Emit3/Semantics/PatternSwitchTests.cs b/src/Compilers/CSharp/Test/Emit3/Semantics/PatternSwitchTests.cs index 8524ef1dff7c2..0b5eea35894cf 100644 --- a/src/Compilers/CSharp/Test/Emit3/Semantics/PatternSwitchTests.cs +++ b/src/Compilers/CSharp/Test/Emit3/Semantics/PatternSwitchTests.cs @@ -325,8 +325,7 @@ public static void Main() } }"; var compilation = CreateCompilation(source, options: TestOptions.DebugExe); - compilation.VerifyDiagnostics( - ); + compilation.VerifyDiagnostics(); } [Fact] @@ -647,8 +646,7 @@ public static void Main(string[] args) } }"; var compilation = CreateCompilation(source, options: TestOptions.DebugExe); - compilation.VerifyDiagnostics( - ); + compilation.VerifyDiagnostics(); } [Fact] @@ -667,8 +665,7 @@ public static void Main(string[] args) } }"; var compilation = CreateCompilation(source, options: TestOptions.DebugExe); - compilation.VerifyDiagnostics( - ); + compilation.VerifyDiagnostics(); } [Fact] @@ -952,8 +949,7 @@ public static void Main() } }"; var compilation = CreateCompilation(source, options: TestOptions.DebugExe); - compilation.VerifyDiagnostics( - ); + compilation.VerifyDiagnostics(); } [Fact] @@ -2661,11 +2657,7 @@ public static async Task SendMessageAsync(object response) "; // Use a compilation profile that supports Task. var compilation = CreateCompilationWithMscorlib461(source, options: TestOptions.ReleaseExe); - compilation.VerifyDiagnostics( - // (12,38): 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. - // public static async Task SendMessageAsync(object response) - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "SendMessageAsync").WithLocation(12, 38) - ); + compilation.VerifyDiagnostics(); var comp = CompileAndVerify(compilation, expectedOutput: @"T default"); @@ -2807,8 +2799,7 @@ static void Main() } "; var compilation = CreateCompilation(source, options: TestOptions.ReleaseExe); - compilation.VerifyDiagnostics( - ); + compilation.VerifyDiagnostics(); var comp = CompileAndVerify(compilation, expectedOutput: @"pass"); } @@ -2835,8 +2826,7 @@ static void Main() } "; var compilation = CreateCompilation(source, options: TestOptions.ReleaseExe); - compilation.VerifyDiagnostics( - ); + compilation.VerifyDiagnostics(); var comp = CompileAndVerify(compilation, expectedOutput: @"pass"); } @@ -2863,8 +2853,7 @@ static void Main() } "; var compilation = CreateCompilation(source, options: TestOptions.ReleaseExe); - compilation.VerifyDiagnostics( - ); + compilation.VerifyDiagnostics(); var comp = CompileAndVerify(compilation, expectedOutput: @"1"); } @@ -2954,8 +2943,7 @@ static void Main() } "; var compilation = CreateCompilation(source, options: TestOptions.ReleaseExe); - compilation.VerifyDiagnostics( - ); + compilation.VerifyDiagnostics(); var comp = CompileAndVerify(compilation, expectedOutput: @"pass"); } diff --git a/src/Compilers/CSharp/Test/IOperation/IOperation/IOperationTests_IForEachLoopStatement.cs b/src/Compilers/CSharp/Test/IOperation/IOperation/IOperationTests_IForEachLoopStatement.cs index b6701cc8eefe6..d5718fa318504 100644 --- a/src/Compilers/CSharp/Test/IOperation/IOperation/IOperationTests_IForEachLoopStatement.cs +++ b/src/Compilers/CSharp/Test/IOperation/IOperation/IOperationTests_IForEachLoopStatement.cs @@ -5866,7 +5866,6 @@ static async Task Main(System.Collections.Generic.IAsyncEnumerable pets) public void AsyncForeach_StructEnumerator() { var compilation = CreateCompilation(@" -#pragma warning disable CS1998 // async method lacks awaits using System.Threading.Tasks; class C { @@ -5990,7 +5989,6 @@ public struct AsyncEnumerator public void AsyncForeach_StructEnumerator_ExplicitAsyncDisposeInterface() { var compilation = CreateCompilation(@" -#pragma warning disable CS1998 // async method lacks awaits using System.Threading.Tasks; class C { diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/AwaitExpressionTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/AwaitExpressionTests.cs index 72a31e7fc05cf..654d83aa8fb81 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/AwaitExpressionTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/AwaitExpressionTests.cs @@ -386,12 +386,6 @@ static int Main() "; var comp = CreateCompilationWithMscorlib461(text, options: TestOptions.ReleaseDll); comp.VerifyEmitDiagnostics( - // (16,62): 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. - // dynamic f = (await GetVal((Func>)(async () => 1)))(); - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "=>").WithLocation(16, 62), - // (20,69): 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. - // dynamic ff = new Func>((Func>)(async () => 1)); - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "=>").WithLocation(20, 69), // (17,13): error CS0656: Missing compiler required member 'Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo.Create' // if (await f == 1) Diagnostic(ErrorCode.ERR_MissingPredefinedMember, "await f").WithArguments("Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo", "Create")); diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/BindingAsyncTasklikeMoreTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/BindingAsyncTasklikeMoreTests.cs index 28ab05cc7959a..18bba00d45b07 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/BindingAsyncTasklikeMoreTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/BindingAsyncTasklikeMoreTests.cs @@ -394,10 +394,8 @@ public void Private() using System.Runtime.CompilerServices; class C { -#pragma warning disable CS1998 static async MyTask F() { } static async MyTask G() { return 3; } -#pragma warning restore CS1998 [AsyncMethodBuilder(typeof(MyTaskMethodBuilder))] private class MyTask { } [AsyncMethodBuilder(typeof(MyTaskMethodBuilder<>))] @@ -455,11 +453,9 @@ static void F(Func> f) { } static void F(Func> f) { } static void M() { -#pragma warning disable CS1998 F(async () => { }); F(async () => { return 3; }); F(async () => { return string.Empty; }); -#pragma warning restore CS1998 } } [AsyncMethodBuilder(typeof(MyTaskMethodBuilder))] @@ -533,12 +529,10 @@ class C { static async void M() { -#pragma warning disable CS1998 async MyTask F() { } async MyTask G(T t) => t; await F(); await G(3); -#pragma warning restore CS1998 } } [AsyncMethodBuilder(typeof(MyTaskMethodBuilder))] @@ -614,11 +608,9 @@ static void F(Func> f) { } static void G(Func> f) { } static void M(object o) { -#pragma warning disable CS1998 F(async () => (dynamic)o); F(async () => new[] { (dynamic)o }); G(async () => o); -#pragma warning restore CS1998 } } [AsyncMethodBuilder(typeof(MyTaskMethodBuilder<>))] @@ -696,10 +688,8 @@ class C { static async void M() { -#pragma warning disable CS1998 async MyTask F() { }; await F(); -#pragma warning restore CS1998 } } [AsyncMethodBuilder(typeof(string))] @@ -718,12 +708,13 @@ namespace System.Runtime.CompilerServices { class AsyncMethodBuilderAttribute : "; var compilation = CreateCompilationWithMscorlib461(source); compilation.VerifyEmitDiagnostics( - // (8,26): error CS0656: Missing compiler required member 'string.Task' + // (7,26): error CS0656: Missing compiler required member 'string.Task' // async MyTask F() { }; - Diagnostic(ErrorCode.ERR_MissingPredefinedMember, "{ }").WithArguments("string", "Task").WithLocation(8, 26), - // (8,26): error CS0656: Missing compiler required member 'string.Create' + Diagnostic(ErrorCode.ERR_MissingPredefinedMember, "{ }").WithArguments("string", "Task").WithLocation(7, 26), + // (7,26): error CS0656: Missing compiler required member 'string.Create' // async MyTask F() { }; - Diagnostic(ErrorCode.ERR_MissingPredefinedMember, "{ }").WithArguments("string", "Create").WithLocation(8, 26)); + Diagnostic(ErrorCode.ERR_MissingPredefinedMember, "{ }").WithArguments("string", "Create").WithLocation(7, 26) + ); } [Fact] @@ -736,10 +727,8 @@ class C { static async void M() { -#pragma warning disable CS1998 async MyTask F(T t) => t; await F(3); -#pragma warning restore CS1998 } } [AsyncMethodBuilder(typeof(IEquatable<>))] @@ -758,12 +747,13 @@ namespace System.Runtime.CompilerServices { class AsyncMethodBuilderAttribute : "; var compilation = CreateCompilationWithMscorlib461(source); compilation.VerifyEmitDiagnostics( - // (8,35): error CS0656: Missing compiler required member 'IEquatable.Task' + // (7,35): error CS0656: Missing compiler required member 'IEquatable.Task' // async MyTask F(T t) => t; - Diagnostic(ErrorCode.ERR_MissingPredefinedMember, "=> t").WithArguments("System.IEquatable", "Task").WithLocation(8, 35), - // (8,35): error CS0656: Missing compiler required member 'IEquatable.Create' + Diagnostic(ErrorCode.ERR_MissingPredefinedMember, "=> t").WithArguments("System.IEquatable", "Task").WithLocation(7, 35), + // (7,35): error CS0656: Missing compiler required member 'IEquatable.Create' // async MyTask F(T t) => t; - Diagnostic(ErrorCode.ERR_MissingPredefinedMember, "=> t").WithArguments("System.IEquatable", "Create").WithLocation(8, 35)); + Diagnostic(ErrorCode.ERR_MissingPredefinedMember, "=> t").WithArguments("System.IEquatable", "Create").WithLocation(7, 35) + ); } [Fact] @@ -776,10 +766,8 @@ class C { static async void M() { -#pragma warning disable CS1998 async MyTask F() { }; await F(); -#pragma warning restore CS1998 } } [AsyncMethodBuilder(typeof(object[]))] @@ -798,9 +786,9 @@ namespace System.Runtime.CompilerServices { class AsyncMethodBuilderAttribute : "; var compilation = CreateCompilationWithMscorlib461(source); compilation.VerifyEmitDiagnostics( - // (8,22): error CS1983: The return type of an async method must be void, Task or Task + // (7,22): error CS1983: The return type of an async method must be void, Task or Task // async MyTask F() { }; - Diagnostic(ErrorCode.ERR_BadAsyncReturn, "{ }").WithLocation(8, 26)); + Diagnostic(ErrorCode.ERR_BadAsyncReturn, "{ }").WithLocation(7, 26)); } [Fact] diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/BindingAsyncTasklikeTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/BindingAsyncTasklikeTests.cs index d34a087079884..75440e3f1aef5 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/BindingAsyncTasklikeTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/BindingAsyncTasklikeTests.cs @@ -107,7 +107,6 @@ private bool VerifyTaskOverloads(string arg, string betterOverload, string worse using System.Threading.Tasks; class Program { - #pragma warning disable CS1998 static void Main() { var s = (<>); diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/BindingAsyncTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/BindingAsyncTests.cs index dd17c9c7c4dcd..a620978925a90 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/BindingAsyncTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/BindingAsyncTests.cs @@ -595,10 +595,7 @@ async static Task F() { } }"; - CreateCompilationWithMscorlib461(source).VerifyDiagnostics( - // (6,23): 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 static Task F() - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "F")); + CreateCompilationWithMscorlib461(source).VerifyDiagnostics(); } [Fact] @@ -697,10 +694,7 @@ unsafe async static Task M1(int* i) { } CreateCompilationWithMscorlib461(source, null, TestOptions.UnsafeReleaseDll).VerifyDiagnostics( // (6,38): error CS4005: Async methods cannot have pointer type parameters // unsafe async static Task M1(int* i) - Diagnostic(ErrorCode.ERR_UnsafeAsyncArgType, "i"), - // (6,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. - // unsafe async static Task M1(ref int* i) - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "M1")); + Diagnostic(ErrorCode.ERR_UnsafeAsyncArgType, "i")); } [Fact] @@ -716,10 +710,7 @@ unsafe async static Task M1(delegate* i) { } CreateCompilationWithMscorlib461(source, null, TestOptions.UnsafeReleaseDll).VerifyDiagnostics( // (6,49): error CS4005: Async methods cannot have pointer type parameters // unsafe async static Task M1(delegate* i) { } - Diagnostic(ErrorCode.ERR_UnsafeAsyncArgType, "i").WithLocation(6, 49), - // (6,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. - // unsafe async static Task M1(delegate* i) { } - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "M1").WithLocation(6, 30) + Diagnostic(ErrorCode.ERR_UnsafeAsyncArgType, "i").WithLocation(6, 49) ); } @@ -766,10 +757,7 @@ unsafe async static Task M1(ref int* i) { } CreateCompilationWithMscorlib461(source, null, TestOptions.UnsafeReleaseDll).VerifyDiagnostics( // (6,42): error CS1988: Async methods cannot have ref, in or out parameters // unsafe async static Task M1(ref int* i) - Diagnostic(ErrorCode.ERR_BadAsyncArgType, "i"), - // (6,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. - // unsafe async static Task M1(ref int* i) - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "M1")); + Diagnostic(ErrorCode.ERR_BadAsyncArgType, "i")); } [Fact] @@ -1602,25 +1590,7 @@ static void Main() Func> f5 = async delegate () { return 1; }; } }"; - CreateCompilationWithMscorlib461(source).VerifyDiagnostics( - // (7,23): 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 static Task M() - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "M").WithLocation(7, 23), - // (13,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. - // Action f1 = async () => new Action(() => { })(); - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "=>").WithLocation(13, 30), - // (14,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. - // Action f2 = async () => { }; - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "=>").WithLocation(14, 30), - // (15,39): 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. - // Func> f3 = async () => { return 1; }; - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "=>").WithLocation(15, 39), - // (16,27): 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. - // Action f4 = async delegate () { }; - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "delegate").WithLocation(16, 27), - // (17,36): 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. - // Func> f5 = async delegate () { return 1; }; - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "delegate").WithLocation(17, 36)); + CreateCompilationWithMscorlib461(source).VerifyDiagnostics(); } [Fact] @@ -1748,10 +1718,7 @@ static int Main() Diagnostic(ErrorCode.WRN_UnobservedAwaitableExpression, "Goo()"), // (27,13): warning CS4014: Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call. // Goo(); - Diagnostic(ErrorCode.WRN_UnobservedAwaitableExpression, "Goo()"), - // (31,32): 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. - // public async Task Goo() - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "Goo")); + Diagnostic(ErrorCode.WRN_UnobservedAwaitableExpression, "Goo()")); } [Fact] @@ -1800,12 +1767,6 @@ static int Main() // (24,9): warning CS4014: Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call. // bar(); Diagnostic(ErrorCode.WRN_UnobservedAwaitableExpression, "bar()"), - // (19,31): 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. - // static async Task Meth() - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "Meth"), - // (29,33): 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. - // static async Task Goo() - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "Goo"), // (36,9): warning CS4014: Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call. // Goo(); Diagnostic(ErrorCode.WRN_UnobservedAwaitableExpression, "Goo()")); @@ -1854,16 +1815,7 @@ static int Main() Diagnostic(ErrorCode.WRN_UnobservedAwaitableExpression, "i.MethExt()").WithLocation(19, 9), // (20,9): warning CS4014: Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call. // Goo(1); - Diagnostic(ErrorCode.WRN_UnobservedAwaitableExpression, "Goo(1)").WithLocation(20, 9), - // (16,26): 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. - // static async Task Meth(T t) - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "Meth").WithLocation(16, 26), - // (26,34): 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. - // return Task.Run(async () => { return t; }); - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "=>").WithLocation(26, 34), - // (10,34): 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. - // return Task.Run(async () => new C1()); - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "=>").WithLocation(10, 34)); + Diagnostic(ErrorCode.WRN_UnobservedAwaitableExpression, "Goo(1)").WithLocation(20, 9)); } [Fact] @@ -1900,27 +1852,18 @@ static int Main() } }"; CreateCompilationWithMscorlib461(source, references: new MetadataReference[] { CSharpRef, SystemCoreRef }).VerifyDiagnostics( - // (20,32): 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. - // static async Task Meth1() - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "Meth1"), // (23,9): warning CS4014: Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call. // Goo(); Diagnostic(ErrorCode.WRN_UnobservedAwaitableExpression, "Goo()"), // (23,9): warning CS0162: Unreachable code detected // Goo(); Diagnostic(ErrorCode.WRN_UnreachableCode, "Goo"), - // (27,33): 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. - // static async Task Meth2() - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "Meth2"), // (29,9): warning CS4014: Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call. // Goo(); Diagnostic(ErrorCode.WRN_UnobservedAwaitableExpression, "Goo()"), // (31,9): warning CS0162: Unreachable code detected // return null; - Diagnostic(ErrorCode.WRN_UnreachableCode, "return"), - // (34,33): 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. - // static async Task Goo() - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "Goo")); + Diagnostic(ErrorCode.WRN_UnreachableCode, "return")); } [Fact] @@ -1958,9 +1901,6 @@ static int Main() // (22,9): warning CS4014: Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call. // Goo(); Diagnostic(ErrorCode.WRN_UnobservedAwaitableExpression, "Goo()"), - // (19,32): 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. - // static async Task Meth1() - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "Meth1"), // (22,9): warning CS0162: Unreachable code detected // Goo(); Diagnostic(ErrorCode.WRN_UnreachableCode, "Goo"), @@ -1969,10 +1909,7 @@ static int Main() Diagnostic(ErrorCode.WRN_UnobservedAwaitableExpression, "Goo()"), // (28,9): warning CS0162: Unreachable code detected // Goo(); - Diagnostic(ErrorCode.WRN_UnreachableCode, "Goo"), - // (31,32): 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. - // static async Task Goo() - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "Goo")); + Diagnostic(ErrorCode.WRN_UnreachableCode, "Goo")); } [Fact] @@ -2217,10 +2154,7 @@ static int Main() Diagnostic(ErrorCode.WRN_UnobservedAwaitableExpression, @"Meth("""")"), // (36,13): warning CS4014: Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call. // Meth((decimal?)2); - Diagnostic(ErrorCode.WRN_UnobservedAwaitableExpression, "Meth((decimal?)2)"), - // (24,23): 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. - // static async Task Goo() - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "Goo")); + Diagnostic(ErrorCode.WRN_UnobservedAwaitableExpression, "Meth((decimal?)2)")); } [Fact] @@ -2394,13 +2328,8 @@ static int Main() Diagnostic(ErrorCode.WRN_UnobservedAwaitableExpression, @"Meth("""", null)").WithLocation(19, 9), // (25,9): warning CS4014: Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call. // Meth(Task.Run(async () => 1), Meth(1)); - Diagnostic(ErrorCode.WRN_UnobservedAwaitableExpression, "Meth(Task.Run(async () => 1), Meth(1))").WithLocation(25, 9), - // (25,32): 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. - // Meth(Task.Run(async () => 1), Meth(1)); - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "=>").WithLocation(25, 32), - // (22,23): 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 Task Goo() - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "Goo").WithLocation(22, 23)); + Diagnostic(ErrorCode.WRN_UnobservedAwaitableExpression, "Meth(Task.Run(async () => 1), Meth(1))").WithLocation(25, 9) + ); } [WorkItem(611150, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/611150")] @@ -2538,10 +2467,8 @@ static int Main() Diagnostic(ErrorCode.ERR_IllegalStatement, "test.Prop"), // (48,9): error CS0201: Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement // test[1]; //error CS0201 - Diagnostic(ErrorCode.ERR_IllegalStatement, "test[1]"), - // (44,23): 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. - // public async Task Goo() - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "Goo")); + Diagnostic(ErrorCode.ERR_IllegalStatement, "test[1]") + ); } [Fact] @@ -3044,9 +2971,6 @@ static int Main() } }"; CreateCompilationWithMscorlib461(source).VerifyDiagnostics( - // (14,34): 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. - // return Task.Run(async () => { return i; }); - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "=>").WithLocation(14, 34), // (21,13): warning CS4014: Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call. // test.Meth(); Diagnostic(ErrorCode.WRN_UnobservedAwaitableExpression, "test.Meth()").WithLocation(21, 13), @@ -3302,10 +3226,8 @@ unsafe async public static void F() Diagnostic(ErrorCode.ERR_BadFixedInitType, "tr"), // (8,31): error CS0210: You must provide an initializer in a fixed or using statement declaration // fixed (TypedReference tr) { } - Diagnostic(ErrorCode.ERR_FixedMustInit, "tr"), - // (6,37): 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. - // unsafe async public static void F() - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "F")); + Diagnostic(ErrorCode.ERR_FixedMustInit, "tr") + ); } [Fact] @@ -3475,10 +3397,7 @@ async void Meth() { } }"; - CreateCompilationWithMscorlib461(source).VerifyDiagnostics( - // (4,16): 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 void Meth() - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "Meth")); + CreateCompilationWithMscorlib461(source).VerifyDiagnostics(); } [Fact, WorkItem(547079, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/547079")] @@ -3514,10 +3433,7 @@ async public static Task Main() { } }"; - CreateCompilationWithMscorlib461(source, options: TestOptions.ReleaseExe, parseOptions: TestOptions.Regular.WithLanguageVersion(LanguageVersion.CSharp7_1)).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)); + CreateCompilationWithMscorlib461(source, options: TestOptions.ReleaseExe, parseOptions: TestOptions.Regular.WithLanguageVersion(LanguageVersion.CSharp7_1)).VerifyDiagnostics(); } [Fact, WorkItem(547081, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/547081")] @@ -3533,9 +3449,6 @@ async public static Task Main() }"; var comp = CreateCompilationWithMscorlib461(source, options: TestOptions.ReleaseExe, parseOptions: TestOptions.Regular.WithLanguageVersion(LanguageVersion.CSharp7)); comp.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,25): error CS8107: Feature 'async main' is not available in C# 7.0. Please use language version 7.1 or greater. // async public static Task Main() Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion7, "Task").WithArguments("async main", "7.1").WithLocation(5, 25), @@ -3561,10 +3474,8 @@ public async void Goo(ref int x) CreateCompilationWithMscorlib461(source).VerifyDiagnostics( // (9,35): error CS1988: Async methods cannot have ref, in or out parameters // public async void Goo(ref int x) - Diagnostic(ErrorCode.ERR_BadAsyncArgType, "x"), - // (9,23): 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. - // public async void Goo(ref int x) - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "Goo")); + Diagnostic(ErrorCode.ERR_BadAsyncArgType, "x") + ); } [Fact] @@ -3726,10 +3637,8 @@ static void Main() CreateCompilationWithMscorlib461(source).VerifyDiagnostics( // (6,29): error CS4010: Cannot convert async anonymous method to delegate type 'Func'. An async anonymous method may return void, Task or Task, none of which are convertible to 'Func'. // Func x = async delegate { throw null; }; - Diagnostic(ErrorCode.ERR_CantConvAsyncAnonFuncReturns, "delegate").WithArguments("anonymous method", "System.Func"), - // (6,29): 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. - // Func x = async delegate { throw null; }; - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "delegate").WithLocation(6, 29)); + Diagnostic(ErrorCode.ERR_CantConvAsyncAnonFuncReturns, "delegate").WithArguments("anonymous method", "System.Func") + ); } [WorkItem(588706, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/588706")] @@ -3904,13 +3813,8 @@ Task YAsync() Diagnostic(ErrorCode.WRN_UnobservedAwaitableExpression, "YAsync()"), // (17,9): warning CS4014: Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call. // XAsync(); // warn - Diagnostic(ErrorCode.WRN_UnobservedAwaitableExpression, "XAsync()"), - // (14,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. - // Action x2 = async () => XAsync(); // warn - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "=>").WithLocation(14, 30), - // (15,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. - // Action y2 = async () => YAsync(); // warn - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "=>").WithLocation(15, 30)); + Diagnostic(ErrorCode.WRN_UnobservedAwaitableExpression, "XAsync()") + ); } [Fact()] @@ -3938,10 +3842,8 @@ static void F(Func f) { } static void F(Func> f) { } static void M() { -#pragma warning disable CS1998 F(async () => { }); F(async () => { return 3; }); -#pragma warning restore CS1998 } }"; var reference = CompileIL(ilSource); diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/BindingAwaitTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/BindingAwaitTests.cs index eb4b6f91c7492..f0edaad44be99 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/BindingAwaitTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/BindingAwaitTests.cs @@ -2690,10 +2690,8 @@ public IVsTask ResolveReferenceAsync() Diagnostic(ErrorCode.ERR_SingleTypeNameNotFound, "IVsTask").WithArguments("IVsTask").WithLocation(4, 12), // (6,21): error CS1061: 'C' does not contain a definition for 'VsTasksService' and no extension method 'VsTasksService' accepting a first argument of type 'C' could be found (are you missing a using directive or an assembly reference?) // return this.VsTasksService.InvokeAsync(async delegate - Diagnostic(ErrorCode.ERR_NoSuchMemberOrExtension, "VsTasksService").WithArguments("C", "VsTasksService").WithLocation(6, 21), - // (6,54): 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. - // return this.VsTasksService.InvokeAsync(async delegate - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "delegate").WithLocation(6, 54)); + Diagnostic(ErrorCode.ERR_NoSuchMemberOrExtension, "VsTasksService").WithArguments("C", "VsTasksService").WithLocation(6, 21) + ); } [Fact, WorkItem(627123, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/627123")] diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/ImplicitObjectCreationTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/ImplicitObjectCreationTests.cs index 59424a53b7fc5..8195479a014c3 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/ImplicitObjectCreationTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/ImplicitObjectCreationTests.cs @@ -1454,8 +1454,7 @@ public static void Main() } "; - var comp = CreateCompilation(source, options: TestOptions.DebugExe).VerifyDiagnostics( - ); + var comp = CreateCompilation(source, options: TestOptions.DebugExe).VerifyDiagnostics(); CompileAndVerify(comp, expectedOutput: "Animal"); } @@ -2267,11 +2266,8 @@ static void M() comp.VerifyDiagnostics( // (8,9): error CS0411: The type arguments for method 'C.F(Task)' cannot be inferred from the usage. Try specifying the type arguments explicitly. // F(async () => new()); - Diagnostic(ErrorCode.ERR_CantInferMethTypeArgs, "F").WithArguments("C.F(System.Threading.Tasks.Task)").WithLocation(8, 9), - // (8,20): 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. - // F(async () => new()); - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "=>").WithLocation(8, 20) - ); + Diagnostic(ErrorCode.ERR_CantInferMethTypeArgs, "F").WithArguments("C.F(System.Threading.Tasks.Task)").WithLocation(8, 9) + ); } [Fact] diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/LambdaTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/LambdaTests.cs index 9de58d02601f9..1a9e8453f077d 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/LambdaTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/LambdaTests.cs @@ -2866,11 +2866,8 @@ void M() Diagnostic(ErrorCode.ERR_NameNotInContext, "error").WithArguments("error").WithLocation(8, 13), // (6,93): error CS4010: Cannot convert async lambda expression to delegate type 'Task>'. An async lambda expression may return void, Task or Task, none of which are convertible to 'Task>'. // System.Func>> x = async x1 => x2 => - Diagnostic(ErrorCode.ERR_CantConvAsyncAnonFuncReturns, "x2 =>").WithArguments("lambda expression", "System.Threading.Tasks.Task>").WithLocation(6, 93), - // (6,90): 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. - // System.Func>> x = async x1 => x2 => - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "=>").WithLocation(6, 90) - ); + Diagnostic(ErrorCode.ERR_CantConvAsyncAnonFuncReturns, "x2 =>").WithArguments("lambda expression", "System.Threading.Tasks.Task>").WithLocation(6, 93) + ); } [Fact, WorkItem(22662, "https://github.com/dotnet/roslyn/issues/22662")] @@ -4061,10 +4058,8 @@ static void Main() Diagnostic(ErrorCode.ERR_SecurityCriticalOrSecuritySafeCriticalOnAsync, "SecurityCritical").WithArguments("SecurityCritical").WithLocation(8, 14), // (9,14): error CS4030: Security attribute 'SecuritySafeCriticalAttribute' cannot be applied to an Async method. // [SecuritySafeCriticalAttribute] // 2 - Diagnostic(ErrorCode.ERR_SecurityCriticalOrSecuritySafeCriticalOnAsync, "SecuritySafeCriticalAttribute").WithArguments("SecuritySafeCriticalAttribute").WithLocation(9, 14), - // (10,22): 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 () => { }; // 3 - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "=>").WithLocation(10, 22)); + Diagnostic(ErrorCode.ERR_SecurityCriticalOrSecuritySafeCriticalOnAsync, "SecuritySafeCriticalAttribute").WithArguments("SecuritySafeCriticalAttribute").WithLocation(9, 14) + ); } [Fact] @@ -5432,10 +5427,8 @@ static void Main() comp.VerifyDiagnostics( // (6,35): error CS1983: The return type of an async method must be void, Task, Task, a task-like type, IAsyncEnumerable, or IAsyncEnumerator // Delegate d = async int () => 0; - Diagnostic(ErrorCode.ERR_BadAsyncReturn, "=>").WithLocation(6, 35), - // (6,35): 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. - // Delegate d = async int () => 0; - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "=>").WithLocation(6, 35)); + Diagnostic(ErrorCode.ERR_BadAsyncReturn, "=>").WithLocation(6, 35) + ); } [Fact] diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/LocalFunctionTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/LocalFunctionTests.cs index 225ccc6466943..be665d4b13813 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/LocalFunctionTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/LocalFunctionTests.cs @@ -52,16 +52,10 @@ async ref System.Threading.Tasks.Task local() { } // (4,11): error CS1073: Unexpected token 'ref' // async ref System.Threading.Tasks.Task M() { } Diagnostic(ErrorCode.ERR_UnexpectedToken, "ref").WithArguments("ref").WithLocation(4, 11), - // (4,43): 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 ref System.Threading.Tasks.Task M() { } - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "M").WithLocation(4, 43), // (10,15): error CS1073: Unexpected token 'ref' // async ref System.Threading.Tasks.Task local() { } - Diagnostic(ErrorCode.ERR_UnexpectedToken, "ref").WithArguments("ref").WithLocation(10, 15), - // (10,47): 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 ref System.Threading.Tasks.Task local() { } - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "local").WithLocation(10, 47) - ); + Diagnostic(ErrorCode.ERR_UnexpectedToken, "ref").WithArguments("ref").WithLocation(10, 15) + ); } [ConditionalFact(typeof(DesktopOnly))] @@ -2067,10 +2061,8 @@ async void local1() // 3 Diagnostic(ErrorCode.ERR_SecurityCriticalOrSecuritySafeCriticalOnAsync, "SecurityCritical").WithArguments("SecurityCritical").WithLocation(10, 10), // (11,10): error CS4030: Security attribute 'SecuritySafeCriticalAttribute' cannot be applied to an Async method. // [SecuritySafeCriticalAttribute] // 2 - Diagnostic(ErrorCode.ERR_SecurityCriticalOrSecuritySafeCriticalOnAsync, "SecuritySafeCriticalAttribute").WithArguments("SecuritySafeCriticalAttribute").WithLocation(11, 10), - // (12,20): 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 void local1() // 3 - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "local1").WithLocation(12, 20)); + Diagnostic(ErrorCode.ERR_SecurityCriticalOrSecuritySafeCriticalOnAsync, "SecuritySafeCriticalAttribute").WithArguments("SecuritySafeCriticalAttribute").WithLocation(11, 10) + ); } [Fact] @@ -5330,10 +5322,8 @@ async Task L(Func t, object p) Diagnostic(ErrorCode.ERR_BadDynamicMethodArgLambda, "async d => await d").WithLocation(8, 37), // (8,35): error CS8322: Cannot pass argument with dynamic type to generic local function 'L' with inferred type arguments. // => await L(async m => L(async d => await d, m), p); - Diagnostic(ErrorCode.ERR_DynamicLocalFunctionTypeParameter, "L(async d => await d, m)").WithArguments("L").WithLocation(8, 35), - // (8,32): 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. - // => await L(async m => L(async d => await d, m), p); - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "=>").WithLocation(8, 32)); + Diagnostic(ErrorCode.ERR_DynamicLocalFunctionTypeParameter, "L(async d => await d, m)").WithArguments("L").WithLocation(8, 35) + ); } [Fact] @@ -7426,7 +7416,7 @@ static void F2() public void AwaitWithinAsyncOuterScope_01() { var source = -@"#pragma warning disable 1998 +@" #pragma warning disable 8321 using System.Threading.Tasks; class Program @@ -7476,7 +7466,7 @@ async void F4() public void AwaitWithinAsyncOuterScope_02() { var source = -@"#pragma warning disable 1998 +@" #pragma warning disable 8321 class Program { @@ -10506,7 +10496,6 @@ public void DefiniteAssignment_01() using System.Threading.Tasks; #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call. -#pragma warning disable 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. public class C { @@ -10530,9 +10519,9 @@ async Task M1() } "; CreateCompilation(text).VerifyDiagnostics( - // (14,27): error CS0165: Use of unassigned local variable 'a' + // (13,27): error CS0165: Use of unassigned local variable 'a' // Console.WriteLine(a); - Diagnostic(ErrorCode.ERR_UseDefViolation, "a").WithArguments("a").WithLocation(14, 27) + Diagnostic(ErrorCode.ERR_UseDefViolation, "a").WithArguments("a").WithLocation(13, 27) ); } @@ -10615,8 +10604,6 @@ public void DefiniteAssignment_04() using System; using System.Threading.Tasks; -#pragma warning disable 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. - public class C { public async Task M() @@ -10639,9 +10626,9 @@ async Task M1() } "; CreateCompilation(text).VerifyDiagnostics( - // (13,27): error CS0165: Use of unassigned local variable 'a' + // (11,27): error CS0165: Use of unassigned local variable 'a' // Console.WriteLine(a); - Diagnostic(ErrorCode.ERR_UseDefViolation, "a").WithArguments("a").WithLocation(13, 27) + Diagnostic(ErrorCode.ERR_UseDefViolation, "a").WithArguments("a").WithLocation(11, 27) ); } diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs index c385f3b09cc5c..6fde5948be15f 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs @@ -8667,10 +8667,7 @@ static async Task G(Func> f) } }"; var comp = CreateCompilationWithMscorlib461(source, parseOptions: TestOptions.Regular7); - comp.VerifyEmitDiagnostics( - // (13,32): 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. - // static async Task G(Func> f) - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "G").WithLocation(13, 32)); + comp.VerifyEmitDiagnostics(); } [Fact, WorkItem(26739, "https://github.com/dotnet/roslyn/issues/26618")] @@ -20420,7 +20417,7 @@ class C public void IdentityConversion_Return_02() { var source = -@"#pragma warning disable 1998 +@" using System.Threading.Tasks; interface I { } interface IIn { } @@ -78342,8 +78339,6 @@ Task F3(Class1 class1, Class3 class3) => "; var comp = CreateCompilation(source); comp.VerifyDiagnostics( - // public async Task F1(Class3 a, int? b) => throw null!; - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "F1").WithLocation(21, 27), // (26,20): error CS1503: Argument 1: cannot convert from 'ConsoleApp1.Class3' to 'ConsoleApp1.Class3' // F1(class3, false ? Class1.Field1 : null); Diagnostic(ErrorCode.ERR_BadArgType, "class3").WithArguments("1", "ConsoleApp1.Class3", "ConsoleApp1.Class3").WithLocation(26, 20), @@ -83200,7 +83195,7 @@ class C public void AsyncTaskMethodReturningNull() { var source = -@"#pragma warning disable 1998 +@" using System.Threading.Tasks; class C { @@ -161447,9 +161442,6 @@ public class C // (5,1): error CS0201: Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement // async (string s) => { try {} catch (System.Exception e) {} }; Diagnostic(ErrorCode.ERR_IllegalStatement, "async (string s) => { try {} catch (System.Exception e) {} }").WithLocation(5, 1), - // (5,18): 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 (string s) => { try {} catch (System.Exception e) {} }; - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "=>").WithLocation(5, 18), // (5,54): warning CS0168: The variable 'e' is declared but never used // async (string s) => { try {} catch (System.Exception e) {} }; Diagnostic(ErrorCode.WRN_UnreferencedVar, "e").WithArguments("e").WithLocation(5, 54) @@ -161474,9 +161466,6 @@ public void Repro66960_2() // (5,1): warning CS0162: Unreachable code detected // async (string s) => { try {} catch (System.Exception e) {} }; Diagnostic(ErrorCode.WRN_UnreachableCode, "async").WithLocation(5, 1), - // (5,18): 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 (string s) => { try {} catch (System.Exception e) {} }; - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "=>").WithLocation(5, 18), // (5,54): warning CS0168: The variable 'e' is declared but never used // async (string s) => { try {} catch (System.Exception e) {} }; Diagnostic(ErrorCode.WRN_UnreferencedVar, "e").WithArguments("e").WithLocation(5, 54) diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/OverloadResolutionTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/OverloadResolutionTests.cs index 2b6444eb74a8f..9b3097ff2ba42 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/OverloadResolutionTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/OverloadResolutionTests.cs @@ -7704,7 +7704,6 @@ class C { static void Main() { -#pragma warning disable 1998 Goo(async () => { return 0; ; }); Goo(async () => { return 0; }); Goo(async () => 0); @@ -7739,7 +7738,6 @@ class C { static void Main() { -#pragma warning disable 1998 Goo(() => async () => { return 0; ; }); Goo(() => async () => { return 0; }); Goo(() => async () => 0); @@ -7771,7 +7769,6 @@ class C { static void Main() { -#pragma warning disable 1998 Goo(async () => { return () => 0; }); Goo(async () => { return () => (short)0; }); } diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/RefLocalsAndReturnsTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/RefLocalsAndReturnsTests.cs index 48e81057165b6..d7fb8d2f7286d 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/RefLocalsAndReturnsTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/RefLocalsAndReturnsTests.cs @@ -3807,10 +3807,7 @@ static async void Goo() } "; - CreateCompilationWithMscorlib46(text).VerifyEmitDiagnostics( - // (6,23): 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. - // static async void Goo() - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "Goo").WithLocation(6, 23)); + CreateCompilationWithMscorlib46(text).VerifyEmitDiagnostics(); } [Fact] diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/TryCatchTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/TryCatchTests.cs index 8a20dbabd67fe..09e6dac3cbdc8 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/TryCatchTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/TryCatchTests.cs @@ -154,11 +154,7 @@ private async Task M(object o) } """; - CompileAndVerify(source, options: TestOptions.DebugDll).VerifyDiagnostics( - // (13,37): 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. - // Func f = async () => - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "=>").WithLocation(13, 37) - ); + CompileAndVerify(source, options: TestOptions.DebugDll).VerifyDiagnostics(); } } } diff --git a/src/Compilers/CSharp/Test/Symbol/Symbols/AssemblyAndNamespaceTests.cs b/src/Compilers/CSharp/Test/Symbol/Symbols/AssemblyAndNamespaceTests.cs index 2f1f955c3ecc0..c7de2d9f5054c 100644 --- a/src/Compilers/CSharp/Test/Symbol/Symbols/AssemblyAndNamespaceTests.cs +++ b/src/Compilers/CSharp/Test/Symbol/Symbols/AssemblyAndNamespaceTests.cs @@ -417,9 +417,6 @@ async void AM() { } // NOTE: As in dev11, we don't consider myTask::System.Threading.Tasks.Task to be // ambiguous with global::System.Threading.Tasks.Task (prefer global). comp.VerifyDiagnostics( - // (7,16): 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 void AM() { } - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "AM"), // (3,1): info CS8019: Unnecessary using directive. // using System.Threading; Diagnostic(ErrorCode.HDN_UnusedUsingDirective, "using System.Threading;"), diff --git a/src/Compilers/CSharp/Test/Symbol/Symbols/ExtendedPartialMethodsTests.cs b/src/Compilers/CSharp/Test/Symbol/Symbols/ExtendedPartialMethodsTests.cs index e3e910f796f3d..023fa631f012a 100644 --- a/src/Compilers/CSharp/Test/Symbol/Symbols/ExtendedPartialMethodsTests.cs +++ b/src/Compilers/CSharp/Test/Symbol/Symbols/ExtendedPartialMethodsTests.cs @@ -1256,10 +1256,7 @@ async partial void M1() { } } "; var comp = CreateCompilation(text); - comp.VerifyDiagnostics( - // (5,24): 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 partial void M1() { } - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "M1").WithLocation(5, 24)); + comp.VerifyDiagnostics(); var method = (MethodSymbol)comp.GetMembers("C.M1")[0]; Assert.True(method.IsPartialDefinition()); @@ -1280,10 +1277,7 @@ private async partial Task M1() { } } "; var comp = CreateCompilation(text, parseOptions: TestOptions.RegularWithExtendedPartialMethods); - comp.VerifyDiagnostics( - // (7,32): 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. - // private async partial Task M1() { } - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "M1").WithLocation(7, 32)); + comp.VerifyDiagnostics(); var method = (MethodSymbol)comp.GetMembers("C.M1")[0]; Assert.True(method.IsPartialDefinition()); @@ -1312,10 +1306,7 @@ public static async Task Main() } "; var verifier = CompileAndVerify(text, parseOptions: TestOptions.RegularWithExtendedPartialMethods, expectedOutput: "1"); - verifier.VerifyDiagnostics( - // (7,31): 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. - // private static async Task CompletedTask() { } - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "CompletedTask").WithLocation(7, 31)); + verifier.VerifyDiagnostics(); var method = (MethodSymbol)verifier.Compilation.GetMembers("C.M1")[0]; Assert.True(method.IsPartialDefinition()); @@ -1753,8 +1744,7 @@ internal partial void M(string s1) { } } "; var comp = CreateCompilation(text, parseOptions: TestOptions.RegularWithExtendedPartialMethods, targetFramework: TargetFramework.NetCoreApp); - comp.VerifyDiagnostics( - ); + comp.VerifyDiagnostics(); } [Fact] @@ -2755,10 +2745,7 @@ public static partial async Task Main() parseOptions: TestOptions.RegularWithExtendedPartialMethods, options: TestOptions.DebugExe, expectedOutput: "1"); - verifier.VerifyDiagnostics( - // (8,38): 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. - // public static partial async Task Main() - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "Main").WithLocation(8, 38)); + verifier.VerifyDiagnostics(); } [Fact] @@ -2804,10 +2791,7 @@ public static partial async Task Main() parseOptions: TestOptions.RegularWithExtendedPartialMethods, options: TestOptions.DebugExe, expectedOutput: "1"); - verifier.VerifyDiagnostics( - // (8,43): 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. - // public static partial async Task Main() - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "Main").WithLocation(8, 43)); + verifier.VerifyDiagnostics(); } [ConditionalFact(typeof(CoreClrOnly))] diff --git a/src/Compilers/CSharp/Test/Symbol/Symbols/ModuleInitializers/SignatureTests.cs b/src/Compilers/CSharp/Test/Symbol/Symbols/ModuleInitializers/SignatureTests.cs index d15621ed9b810..d75c3b1618188 100644 --- a/src/Compilers/CSharp/Test/Symbol/Symbols/ModuleInitializers/SignatureTests.cs +++ b/src/Compilers/CSharp/Test/Symbol/Symbols/ModuleInitializers/SignatureTests.cs @@ -196,10 +196,8 @@ namespace System.Runtime.CompilerServices { class ModuleInitializerAttribute : S compilation.VerifyEmitDiagnostics( // (6,6): error CS8815: Module initializer method 'M' must be static, and non-virtual, must have no parameters, and must return 'void' // [ModuleInitializer] - Diagnostic(ErrorCode.ERR_ModuleInitializerMethodMustBeStaticParameterlessVoid, "ModuleInitializer").WithArguments("M").WithLocation(7, 6), - // (8,32): 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. - // internal static async Task M() { } - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "M").WithLocation(8, 32)); + Diagnostic(ErrorCode.ERR_ModuleInitializerMethodMustBeStaticParameterlessVoid, "ModuleInitializer").WithArguments("M").WithLocation(7, 6) + ); } [Fact] diff --git a/src/Compilers/CSharp/Test/Symbol/Symbols/Source/DelegateTests.cs b/src/Compilers/CSharp/Test/Symbol/Symbols/Source/DelegateTests.cs index 8236a73106caa..aea7c81f322db 100644 --- a/src/Compilers/CSharp/Test/Symbol/Symbols/Source/DelegateTests.cs +++ b/src/Compilers/CSharp/Test/Symbol/Symbols/Source/DelegateTests.cs @@ -714,10 +714,8 @@ class C CreateCompilation(source).VerifyDiagnostics( // (4,17): error CS1988: Async methods cannot have ref, in or out parameters // D d = async delegate { }; - Diagnostic(ErrorCode.ERR_BadAsyncArgType, "delegate").WithLocation(4, 17), - // (4,17): 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. - // D d = async delegate { }; - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "delegate").WithLocation(4, 17)); + Diagnostic(ErrorCode.ERR_BadAsyncArgType, "delegate").WithLocation(4, 17) + ); } [Fact] diff --git a/src/Compilers/CSharp/Test/Symbol/Symbols/Source/MethodTests.cs b/src/Compilers/CSharp/Test/Symbol/Symbols/Source/MethodTests.cs index fd31ba1327dbf..7a04fd7df3dd7 100644 --- a/src/Compilers/CSharp/Test/Symbol/Symbols/Source/MethodTests.cs +++ b/src/Compilers/CSharp/Test/Symbol/Symbols/Source/MethodTests.cs @@ -2111,10 +2111,7 @@ partial class C async partial void M() { } } "; - CreateCompilation(source).VerifyDiagnostics( - // (15,24): 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 partial void M() { } - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "M")); + CreateCompilation(source).VerifyDiagnostics(); } [WorkItem(910100, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/910100")] @@ -2267,9 +2264,6 @@ static async ref int M() { } // (4,18): error CS1073: Unexpected token 'ref' // static async ref int M() { } Diagnostic(ErrorCode.ERR_UnexpectedToken, "ref").WithArguments("ref").WithLocation(4, 18), - // (4,26): 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. - // static async ref int M() { } - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "M").WithLocation(4, 26), // (4,26): error CS0161: 'C.M()': not all code paths return a value // static async ref int M() { } Diagnostic(ErrorCode.ERR_ReturnExpected, "M").WithArguments("C.M()").WithLocation(4, 26) @@ -2291,9 +2285,6 @@ static async ref readonly int M() { } // (4,18): error CS1073: Unexpected token 'ref' // static async ref readonly int M() { } Diagnostic(ErrorCode.ERR_UnexpectedToken, "ref").WithArguments("ref").WithLocation(4, 18), - // (4,35): 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. - // static async ref readonly int M() { } - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "M").WithLocation(4, 35), // (4,35): error CS0161: 'C.M()': not all code paths return a value // static async ref readonly int M() { } Diagnostic(ErrorCode.ERR_ReturnExpected, "M").WithArguments("C.M()").WithLocation(4, 35) diff --git a/src/Compilers/CSharp/Test/Syntax/Parsing/AnonymousFunctionParsingTests.cs b/src/Compilers/CSharp/Test/Syntax/Parsing/AnonymousFunctionParsingTests.cs index 08ed75807b1ca..986af50abc276 100644 --- a/src/Compilers/CSharp/Test/Syntax/Parsing/AnonymousFunctionParsingTests.cs +++ b/src/Compilers/CSharp/Test/Syntax/Parsing/AnonymousFunctionParsingTests.cs @@ -113,10 +113,8 @@ void M1() CreateCompilation(test, parseOptions: TestOptions.Regular8).GetDiagnostics().Verify( // (8,26): error CS1004: Duplicate 'async' modifier // Action v = async async delegate() { }; - Diagnostic(ErrorCode.ERR_DuplicateModifier, "async").WithArguments("async").WithLocation(8, 26), - // (8,32): 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. - // Action v = async async delegate() { }; - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "delegate").WithLocation(8, 32)); + Diagnostic(ErrorCode.ERR_DuplicateModifier, "async").WithArguments("async").WithLocation(8, 26) + ); } [Fact] @@ -311,10 +309,8 @@ void M1() CreateCompilation(test, parseOptions: TestOptions.Regular8).GetDiagnostics().Verify( // (8,20): error CS8400: Feature 'static anonymous function' is not available in C# 8.0. Please use language version 9.0 or greater. // Action v = static async delegate() { }; - Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion8, "static").WithArguments("static anonymous function", "9.0").WithLocation(8, 20), - // (8,33): 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. - // Action v = static async delegate() { }; - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "delegate").WithLocation(8, 33)); + Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion8, "static").WithArguments("static anonymous function", "9.0").WithLocation(8, 20) + ); } [Fact] @@ -412,10 +408,8 @@ void M1() CreateCompilation(test, parseOptions: TestOptions.Regular8).GetDiagnostics().Verify( // (8,20): error CS8400: Feature 'static anonymous function' is not available in C# 8.0. Please use language version 9.0 or greater. // Action v = static async delegate() { }; - Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion8, "static").WithArguments("static anonymous function", "9.0").WithLocation(8, 20), - // (8,33): 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. - // Action v = static async delegate() { }; - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "delegate").WithLocation(8, 33)); + Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion8, "static").WithArguments("static anonymous function", "9.0").WithLocation(8, 20) + ); } [Fact] @@ -765,10 +759,7 @@ void M1() } EOF(); - CreateCompilation(test, parseOptions: TestOptions.Regular8).GetDiagnostics().Verify( - // (9,46): 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. - // Func> v = async async => async; - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "=>").WithLocation(9, 46)); + CreateCompilation(test, parseOptions: TestOptions.Regular8).GetDiagnostics().Verify(); } [Fact] @@ -2578,10 +2569,8 @@ void M1() CreateCompilation(test, parseOptions: TestOptions.Regular8).GetDiagnostics().Verify( // (9,34): error CS8400: Feature 'static anonymous function' is not available in C# 8.0. Please use language version 9.0 or greater. // Func> v = static async async => async; - Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion8, "static").WithArguments("static anonymous function", "9.0").WithLocation(9, 34), - // (9,53): 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. - // Func> v = static async async => async; - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "=>").WithLocation(9, 53)); + Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion8, "static").WithArguments("static anonymous function", "9.0").WithLocation(9, 34) + ); } [Fact] @@ -2726,10 +2715,8 @@ void M1() CreateCompilation(test, parseOptions: TestOptions.Regular8).GetDiagnostics().Verify( // (9,40): error CS8400: Feature 'static anonymous function' is not available in C# 8.0. Please use language version 9.0 or greater. // Func> v = async static async => async; - Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion8, "static").WithArguments("static anonymous function", "9.0").WithLocation(9, 40), - // (9,53): 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. - // Func> v = async static async => async; - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "=>").WithLocation(9, 53)); + Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion8, "static").WithArguments("static anonymous function", "9.0").WithLocation(9, 40) + ); } [Fact] @@ -2878,10 +2865,8 @@ void M1() Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion8, "static").WithArguments("static anonymous function", "9.0").WithLocation(9, 40), // (9,47): error CS1004: Duplicate 'async' modifier // Func> v = async static async async => async; - Diagnostic(ErrorCode.ERR_DuplicateModifier, "async").WithArguments("async").WithLocation(9, 47), - // (9,59): 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. - // Func> v = async static async async => async; - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "=>").WithLocation(9, 59)); + Diagnostic(ErrorCode.ERR_DuplicateModifier, "async").WithArguments("async").WithLocation(9, 47) + ); } [Fact] @@ -3137,10 +3122,7 @@ void M1() } EOF(); - CreateCompilation(test, parseOptions: TestOptions.Regular8).GetDiagnostics().Verify( - // (9,48): 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. - // Func> v = async (async) => async; - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "=>").WithLocation(9, 48)); + CreateCompilation(test, parseOptions: TestOptions.Regular8).GetDiagnostics().Verify(); } [Fact] @@ -3404,10 +3386,8 @@ void M1() CreateCompilation(test, parseOptions: TestOptions.Regular8).GetDiagnostics().Verify( // (9,34): error CS8400: Feature 'static anonymous function' is not available in C# 8.0. Please use language version 9.0 or greater. // Func> v = static async (async) => async; - Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion8, "static").WithArguments("static anonymous function", "9.0").WithLocation(9, 34), - // (9,55): 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. - // Func> v = static async (async) => async; - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "=>").WithLocation(9, 55)); + Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion8, "static").WithArguments("static anonymous function", "9.0").WithLocation(9, 34) + ); } [Fact] @@ -3557,10 +3537,8 @@ void M1() CreateCompilation(test, parseOptions: TestOptions.Regular8).GetDiagnostics().Verify( // (9,40): error CS8400: Feature 'static anonymous function' is not available in C# 8.0. Please use language version 9.0 or greater. // Func> v = async static (async) => async; - Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion8, "static").WithArguments("static anonymous function", "9.0").WithLocation(9, 40), - // (9,55): 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. - // Func> v = async static (async) => async; - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "=>").WithLocation(9, 55)); + Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion8, "static").WithArguments("static anonymous function", "9.0").WithLocation(9, 40) + ); } [Fact] @@ -3714,10 +3692,8 @@ void M1() Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion8, "static").WithArguments("static anonymous function", "9.0").WithLocation(9, 40), // (9,47): error CS1004: Duplicate 'async' modifier // Func> v = async static async (async) => async; - Diagnostic(ErrorCode.ERR_DuplicateModifier, "async").WithArguments("async").WithLocation(9, 47), - // (9,61): 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. - // Func> v = async static async (async) => async; - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "=>").WithLocation(9, 61)); + Diagnostic(ErrorCode.ERR_DuplicateModifier, "async").WithArguments("async").WithLocation(9, 47) + ); } [Fact] @@ -3991,10 +3967,7 @@ void M1() } EOF(); - CreateCompilation(test, parseOptions: TestOptions.Regular8).GetDiagnostics().Verify( - // (10,38): 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. - // Func> v = async () => a; - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "=>").WithLocation(10, 38)); + CreateCompilation(test, parseOptions: TestOptions.Regular8).GetDiagnostics().Verify(); } [Fact] @@ -4276,10 +4249,8 @@ void M1() CreateCompilation(test, parseOptions: TestOptions.Regular8).GetDiagnostics().Verify( // (10,29): error CS8400: Feature 'static anonymous function' is not available in C# 8.0. Please use language version 9.0 or greater. // Func> v = static async () => a; - Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion8, "static").WithArguments("static anonymous function", "9.0").WithLocation(10, 29), - // (10,45): 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. - // Func> v = static async () => a; - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "=>").WithLocation(10, 45)); + Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion8, "static").WithArguments("static anonymous function", "9.0").WithLocation(10, 29) + ); } [Fact] @@ -4438,10 +4409,8 @@ void M1() CreateCompilation(test, parseOptions: TestOptions.Regular8).GetDiagnostics().Verify( // (10,35): error CS8400: Feature 'static anonymous function' is not available in C# 8.0. Please use language version 9.0 or greater. // Func> v = async static () => a; - Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion8, "static").WithArguments("static anonymous function", "9.0").WithLocation(10, 35), - // (10,45): 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. - // Func> v = async static () => a; - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "=>").WithLocation(10, 45)); + Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion8, "static").WithArguments("static anonymous function", "9.0").WithLocation(10, 35) + ); } [Fact] @@ -4604,10 +4573,8 @@ void M1() Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion8, "static").WithArguments("static anonymous function", "9.0").WithLocation(10, 35), // (10,42): error CS1004: Duplicate 'async' modifier // Func> v = async static async () => a; - Diagnostic(ErrorCode.ERR_DuplicateModifier, "async").WithArguments("async").WithLocation(10, 42), - // (10,51): 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. - // Func> v = async static async () => a; - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "=>").WithLocation(10, 51)); + Diagnostic(ErrorCode.ERR_DuplicateModifier, "async").WithArguments("async").WithLocation(10, 42) + ); } } } diff --git a/src/Compilers/CSharp/Test/Syntax/Parsing/FileModifierParsingTests.cs b/src/Compilers/CSharp/Test/Syntax/Parsing/FileModifierParsingTests.cs index 4043dbe639c76..b84541b3f9c06 100644 --- a/src/Compilers/CSharp/Test/Syntax/Parsing/FileModifierParsingTests.cs +++ b/src/Compilers/CSharp/Test/Syntax/Parsing/FileModifierParsingTests.cs @@ -1009,9 +1009,6 @@ async file void M() { } // (3,21): error CS0106: The modifier 'file' is not valid for this item // async file void M() { } Diagnostic(ErrorCode.ERR_BadMemberFlag, "M").WithArguments("file").WithLocation(3, 21), - // (3,21): 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 file void M() { } - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "M").WithLocation(3, 21) }); N(SyntaxKind.CompilationUnit); { diff --git a/src/Compilers/CSharp/Test/Syntax/Parsing/LocalFunctionParsingTests.cs b/src/Compilers/CSharp/Test/Syntax/Parsing/LocalFunctionParsingTests.cs index 54e8d9ddc16ce..11142f244eb08 100644 --- a/src/Compilers/CSharp/Test/Syntax/Parsing/LocalFunctionParsingTests.cs +++ b/src/Compilers/CSharp/Test/Syntax/Parsing/LocalFunctionParsingTests.cs @@ -1806,44 +1806,26 @@ async static void F2() { } // (5,9): error CS8370: Feature 'static local functions' is not available in C# 7.3. Please use language version 8.0 or greater. // static async void F1() { } Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion7_3, "static").WithArguments("static local functions", "8.0").WithLocation(5, 9), - // (5,27): 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. - // static async void F1() { } - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "F1").WithLocation(5, 27), // (5,27): warning CS8321: The local function 'F1' is declared but never used // static async void F1() { } Diagnostic(ErrorCode.WRN_UnreferencedLocalFunction, "F1").WithArguments("F1").WithLocation(5, 27), // (6,15): error CS8370: Feature 'static local functions' is not available in C# 7.3. Please use language version 8.0 or greater. // async static void F2() { } Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion7_3, "static").WithArguments("static local functions", "8.0").WithLocation(6, 15), - // (6,27): 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 static void F2() { } - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "F2").WithLocation(6, 27), // (6,27): warning CS8321: The local function 'F2' is declared but never used // async static void F2() { } Diagnostic(ErrorCode.WRN_UnreferencedLocalFunction, "F2").WithArguments("F2").WithLocation(6, 27)); CreateCompilation(text, parseOptions: TestOptions.Regular8).VerifyDiagnostics( - // (5,27): 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. - // static async void F1() { } - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "F1").WithLocation(5, 27), // (5,27): warning CS8321: The local function 'F1' is declared but never used // static async void F1() { } Diagnostic(ErrorCode.WRN_UnreferencedLocalFunction, "F1").WithArguments("F1").WithLocation(5, 27), - // (6,27): 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 static void F2() { } - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "F2").WithLocation(6, 27), // (6,27): warning CS8321: The local function 'F2' is declared but never used // async static void F2() { } Diagnostic(ErrorCode.WRN_UnreferencedLocalFunction, "F2").WithArguments("F2").WithLocation(6, 27)); CreateCompilation(text, parseOptions: TestOptions.Regular9).VerifyDiagnostics( - // (5,27): 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. - // static async void F1() { } - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "F1").WithLocation(5, 27), // (5,27): warning CS8321: The local function 'F1' is declared but never used // static async void F1() { } Diagnostic(ErrorCode.WRN_UnreferencedLocalFunction, "F1").WithArguments("F1").WithLocation(5, 27), - // (6,27): 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 static void F2() { } - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "F2").WithLocation(6, 27), // (6,27): warning CS8321: The local function 'F2' is declared but never used // async static void F2() { } Diagnostic(ErrorCode.WRN_UnreferencedLocalFunction, "F2").WithArguments("F2").WithLocation(6, 27)); @@ -1964,9 +1946,6 @@ static async static void F2() { } // (6,22): error CS8370: Feature 'static local functions' is not available in C# 7.3. Please use language version 8.0 or greater. // static async static void F2() { } Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion7_3, "static").WithArguments("static local functions", "8.0").WithLocation(6, 22), - // (6,34): 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. - // static async static void F2() { } - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "F2").WithLocation(6, 34), // (6,34): warning CS8321: The local function 'F2' is declared but never used // static async static void F2() { } Diagnostic(ErrorCode.WRN_UnreferencedLocalFunction, "F2").WithArguments("F2").WithLocation(6, 34)); @@ -1986,9 +1965,6 @@ static async static void F2() { } // (6,22): error CS1004: Duplicate 'static' modifier // static async static void F2() { } Diagnostic(ErrorCode.ERR_DuplicateModifier, "static").WithArguments("static").WithLocation(6, 22), - // (6,34): 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. - // static async static void F2() { } - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "F2").WithLocation(6, 34), // (6,34): warning CS8321: The local function 'F2' is declared but never used // static async static void F2() { } Diagnostic(ErrorCode.WRN_UnreferencedLocalFunction, "F2").WithArguments("F2").WithLocation(6, 34)); @@ -2008,9 +1984,6 @@ static async static void F2() { } // (6,22): error CS1004: Duplicate 'static' modifier // static async static void F2() { } Diagnostic(ErrorCode.ERR_DuplicateModifier, "static").WithArguments("static").WithLocation(6, 22), - // (6,34): 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. - // static async static void F2() { } - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "F2").WithLocation(6, 34), // (6,34): warning CS8321: The local function 'F2' is declared but never used // static async static void F2() { } Diagnostic(ErrorCode.WRN_UnreferencedLocalFunction, "F2").WithArguments("F2").WithLocation(6, 34)); @@ -2118,7 +2091,7 @@ class Program { void M() { - #pragma warning disable 1998, 8321 + #pragma warning disable 8321 async async void F() { } } } @@ -2195,7 +2168,7 @@ class Program { void M() { - #pragma warning disable 1998, 8321 + #pragma warning disable 8321 async async async void F() { } } } @@ -2279,7 +2252,7 @@ class Program { void M() { - #pragma warning disable 1998, 8321 + #pragma warning disable 8321 async async async async void F() { } } } @@ -2370,7 +2343,7 @@ class Program { void M() { - #pragma warning disable 1998, 8321 + #pragma warning disable 8321 async async async async async void F() { } } } diff --git a/src/Compilers/CSharp/Test/Syntax/Parsing/ParserErrorMessageTests.cs b/src/Compilers/CSharp/Test/Syntax/Parsing/ParserErrorMessageTests.cs index 18c269a58edc7..76b9f57da9d93 100644 --- a/src/Compilers/CSharp/Test/Syntax/Parsing/ParserErrorMessageTests.cs +++ b/src/Compilers/CSharp/Test/Syntax/Parsing/ParserErrorMessageTests.cs @@ -5977,10 +5977,7 @@ async void M() { } var tree = SyntaxFactory.ParseSyntaxTree(text, options: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp5)); tree.GetCompilationUnitRoot().GetDiagnostics().Verify(); - CreateCompilation(text, parseOptions: TestOptions.Regular5).VerifyDiagnostics( - // (4,16): 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 void M() { } - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "M").WithLocation(4, 16)); + CreateCompilation(text, parseOptions: TestOptions.Regular5).VerifyDiagnostics(); tree = SyntaxFactory.ParseSyntaxTree(text, options: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp3)); tree.GetCompilationUnitRoot().GetDiagnostics().Verify(); @@ -5988,10 +5985,8 @@ async void M() { } CreateCompilation(text, parseOptions: TestOptions.Regular3).VerifyDiagnostics( // (4,16): error CS8024: Feature 'async function' is not available in C# 3. Please use language version 5 or greater. // async void M() { } - Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion3, "M").WithArguments("async function", "5").WithLocation(4, 16), - // (4,16): 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 void M() { } - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "M").WithLocation(4, 16)); + Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion3, "M").WithArguments("async function", "5").WithLocation(4, 16) + ); } [Fact, WorkItem(529870, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/529870")] @@ -6005,20 +6000,15 @@ async static void M() { } "; var tree = SyntaxFactory.ParseSyntaxTree(text, options: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp5)); tree.GetCompilationUnitRoot().GetDiagnostics().Verify(); - CreateCompilation(text, parseOptions: TestOptions.Regular5).VerifyDiagnostics( - // (4,23): 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 static void M() { } - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "M").WithLocation(4, 23)); + CreateCompilation(text, parseOptions: TestOptions.Regular5).VerifyDiagnostics(); tree = SyntaxFactory.ParseSyntaxTree(text, options: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp3)); tree.GetCompilationUnitRoot().GetDiagnostics().Verify(); CreateCompilation(text, parseOptions: TestOptions.Regular3).VerifyDiagnostics( // (4,23): error CS8024: Feature 'async function' is not available in C# 3. Please use language version 5 or greater. // async static void M() { } - Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion3, "M").WithArguments("async function", "5").WithLocation(4, 23), - // (4,23): 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 static void M() { } - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "M").WithLocation(4, 23)); + Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion3, "M").WithArguments("async function", "5").WithLocation(4, 23) + ); } [Fact] @@ -6041,10 +6031,8 @@ static void Main() Diagnostic(ErrorCode.ERR_SingleTypeNameNotFound, "Func>").WithArguments("Func<,>").WithLocation(6, 9), // (6,19): error CS0246: The type or namespace name 'Task<>' could not be found (are you missing a using directive or an assembly reference?) // Func> f = async x => x; - Diagnostic(ErrorCode.ERR_SingleTypeNameNotFound, "Task").WithArguments("Task<>").WithLocation(6, 19), - // (6,42): 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. - // Func> f = async x => x; - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "=>").WithLocation(6, 42)); + Diagnostic(ErrorCode.ERR_SingleTypeNameNotFound, "Task").WithArguments("Task<>").WithLocation(6, 19) + ); tree = SyntaxFactory.ParseSyntaxTree(text, options: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp4)); tree.GetCompilationUnitRoot().GetDiagnostics().Verify(); @@ -6057,10 +6045,8 @@ static void Main() Diagnostic(ErrorCode.ERR_SingleTypeNameNotFound, "Task").WithArguments("Task<>").WithLocation(6, 19), // (6,34): error CS8025: Feature 'async function' is not available in C# 4. Please use language version 5 or greater. // Func> f = async x => x; - Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion4, "async").WithArguments("async function", "5").WithLocation(6, 34), - // (6,42): 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. - // Func> f = async x => x; - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "=>").WithLocation(6, 42)); + Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion4, "async").WithArguments("async function", "5").WithLocation(6, 34) + ); } [Fact] @@ -6083,10 +6069,8 @@ static void Main() Diagnostic(ErrorCode.ERR_SingleTypeNameNotFound, "Func>").WithArguments("Func<,>").WithLocation(6, 9), // (6,19): error CS0246: The type or namespace name 'Task<>' could not be found (are you missing a using directive or an assembly reference?) // Func> f = async delegate (int x) { return x; }; - Diagnostic(ErrorCode.ERR_SingleTypeNameNotFound, "Task").WithArguments("Task<>").WithLocation(6, 19), - // (6,40): 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. - // Func> f = async delegate (int x) { return x; }; - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "delegate").WithLocation(6, 40)); + Diagnostic(ErrorCode.ERR_SingleTypeNameNotFound, "Task").WithArguments("Task<>").WithLocation(6, 19) + ); tree = SyntaxFactory.ParseSyntaxTree(text, options: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp4)); tree.GetCompilationUnitRoot().GetDiagnostics().Verify(); @@ -6099,10 +6083,8 @@ static void Main() Diagnostic(ErrorCode.ERR_SingleTypeNameNotFound, "Task").WithArguments("Task<>").WithLocation(6, 19), // (6,34): error CS8025: Feature 'async function' is not available in C# 4. Please use language version 5 or greater. // Func> f = async delegate (int x) { return x; }; - Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion4, "async").WithArguments("async function", "5").WithLocation(6, 34), - // (6,40): 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. - // Func> f = async delegate (int x) { return x; }; - Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "delegate").WithLocation(6, 40)); + Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion4, "async").WithArguments("async function", "5").WithLocation(6, 34) + ); } [Fact] diff --git a/src/Dependencies/Threading/IAsyncEnumerableExtensions.cs b/src/Dependencies/Threading/IAsyncEnumerableExtensions.cs index 9d0447c685262..9e708791a002c 100644 --- a/src/Dependencies/Threading/IAsyncEnumerableExtensions.cs +++ b/src/Dependencies/Threading/IAsyncEnumerableExtensions.cs @@ -23,6 +23,7 @@ public static async Task> ToImmutableArrayAsync(this IAsync return result.ToImmutableAndClear(); } + // Remove after .NET 10, https://github.com/dotnet/roslyn/issues/80198 #pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously #pragma warning disable VSTHRD200 // Use "Async" suffix for async methods public static async IAsyncEnumerable AsAsyncEnumerable(this IEnumerable source) diff --git a/src/LanguageServer/ProtocolUnitTests/CodeActions/CodeActionsTests.cs b/src/LanguageServer/ProtocolUnitTests/CodeActions/CodeActionsTests.cs index 20f0f483ebb27..639deea8e432e 100644 --- a/src/LanguageServer/ProtocolUnitTests/CodeActions/CodeActionsTests.cs +++ b/src/LanguageServer/ProtocolUnitTests/CodeActions/CodeActionsTests.cs @@ -138,43 +138,6 @@ void M() Assert.Equal(AddImportDiagnosticIds.CS0103, addImport.Diagnostics.Single().Code!.Value); } - [Theory, CombinatorialData] - public async Task TestNoSuppressionFixerInStandardLSP(bool mutatingLspWorkspace) - { - var markup = """ - class ABC - { - private static async void {|caret:XYZ|}() - { - } - } - """; - - await using var testLspServer = await CreateTestLspServerAsync(markup, mutatingLspWorkspace); - - var caret = testLspServer.GetLocations("caret").Single(); - var codeActionParams = new CodeActionParams - { - TextDocument = CreateTextDocumentIdentifier(caret.DocumentUri), - Range = caret.Range, - Context = new CodeActionContext - { - Diagnostics = - [ - new LSP.Diagnostic - { - // async method lack of await. - Code = "CS1998" - } - ] - } - }; - - var results = await RunGetCodeActionsAsync(testLspServer, codeActionParams); - Assert.Equal(3, results.Length); - Assert.Equal("Make method synchronous", results[0].Title); - } - [Theory, CombinatorialData] public async Task TestStandardLspNestedCodeAction(bool mutatingLspWorkspace) { @@ -227,8 +190,9 @@ public async Task TestStandardLspNestedFixAllCodeAction(bool mutatingLspWorkspac var markup = """ class ABC { - private static async void {|caret:XYZ|}() + private static async void XYZ() { + {|caret:System.Threading.Tasks.Task.Yield()|}; } } """; @@ -246,17 +210,17 @@ class ABC [ new LSP.Diagnostic { - // async method lack of await. - Code = "CS1998" + // Task-returning method not awaited + Code = "CS4014" } ] } }; var results = await RunGetCodeActionsAsync(testLspServer, codeActionParams); - Assert.Equal(3, results.Length); - Assert.Equal("Suppress or configure issues", results[2].Title); - var data = GetCodeActionResolveData(results[2]); + Assert.Equal(10, results.Length); + Assert.Equal("Suppress or configure issues", results[9].Title); + var data = GetCodeActionResolveData(results[9]); Assert.NotNull(data); // Asserts that there are NestedActions present diff --git a/src/LanguageServer/ProtocolUnitTests/SemanticTokens/SemanticTokensRangeTests.cs b/src/LanguageServer/ProtocolUnitTests/SemanticTokens/SemanticTokensRangeTests.cs index fbdc1a5b01cf2..fd994d88a0028 100644 --- a/src/LanguageServer/ProtocolUnitTests/SemanticTokens/SemanticTokensRangeTests.cs +++ b/src/LanguageServer/ProtocolUnitTests/SemanticTokens/SemanticTokensRangeTests.cs @@ -99,7 +99,6 @@ private void __RazorDirectiveTokenHelpers__() { #pragma warning disable 0414 private static object __o = null; #pragma warning restore 0414 - #pragma warning disable 1998 public async override global::System.Threading.Tasks.Task ExecuteAsync() { #nullable restore @@ -122,7 +121,7 @@ private void __RazorDirectiveTokenHelpers__() { var document = testLspServer.GetCurrentSolution().Projects.First().Documents.First(); ImmutableArray spans = [ new LinePositionSpan(new LinePosition(12, 0), new LinePosition(13, 0)), - new LinePositionSpan(new LinePosition(29, 0), new LinePosition(30, 0)), + new LinePositionSpan(new LinePosition(28, 0), new LinePosition(29, 0)), ]; var options = ClassificationOptions.Default; @@ -141,7 +140,7 @@ private void __RazorDirectiveTokenHelpers__() { 0, 2, 1, tokenTypeToIndex[SemanticTokenTypes.Operator], 0, // '=' 0, 2, 1, tokenTypeToIndex[SemanticTokenTypes.Number], 0, // '1' 0, 1, 1, tokenTypeToIndex[ClassificationTypeNames.Punctuation], 0, // ';' - 17, 3, 3, tokenTypeToIndex[ClassificationTypeNames.Keyword], 0, // 'var' + 16, 3, 3, tokenTypeToIndex[ClassificationTypeNames.Keyword], 0, // 'var' 0, 4, 1, tokenTypeToIndex[ClassificationTypeNames.LocalName], 0, // 'x' 0, 2, 1, tokenTypeToIndex[SemanticTokenTypes.Operator], 0, // '=' ]; @@ -156,7 +155,7 @@ private void __RazorDirectiveTokenHelpers__() { 0, 2, 1, tokenTypeToIndex[SemanticTokenTypes.Operator], 0, // '=' 0, 2, 1, tokenTypeToIndex[SemanticTokenTypes.Number], 0, // '1' 0, 1, 1, tokenTypeToIndex[ClassificationTypeNames.Punctuation], 0, // ';' - 17, 3, 3, tokenTypeToIndex[SemanticTokenTypes.Keyword], 0, // 'var' + 16, 3, 3, tokenTypeToIndex[SemanticTokenTypes.Keyword], 0, // 'var' 0, 4, 1, tokenTypeToIndex[SemanticTokenTypes.Variable], 0, // 'x' 0, 2, 1, tokenTypeToIndex[SemanticTokenTypes.Operator], 0, // '=' ]; diff --git a/src/Scripting/CSharpTest/CommandLineRunnerTests.cs b/src/Scripting/CSharpTest/CommandLineRunnerTests.cs index 874cd142ca8d1..2d3c526ec247d 100644 --- a/src/Scripting/CSharpTest/CommandLineRunnerTests.cs +++ b/src/Scripting/CSharpTest/CommandLineRunnerTests.cs @@ -52,9 +52,6 @@ select x * x . {{ . return new int[] {{ 1, 2, 3, 4, 5 }}; . }} -«Yellow» -(1,19): warning CS1998: {CSharpResources.WRN_AsyncLacksAwaits} -«Gray» > from x in await GetStuffAsync() . where x > 2 . select x * x @@ -62,7 +59,7 @@ . select x * x > ", runner.Console.Out.ToString()); AssertEx.AssertEqualToleratingWhitespaceDifferences( - $@"(1,19): warning CS1998: {CSharpResources.WRN_AsyncLacksAwaits}", + "", runner.Console.Error.ToString()); } diff --git a/src/Tools/BuildActionTelemetryTable/CodeActionDescriptions.cs b/src/Tools/BuildActionTelemetryTable/CodeActionDescriptions.cs index a90bb163156db..3b324897b7657 100644 --- a/src/Tools/BuildActionTelemetryTable/CodeActionDescriptions.cs +++ b/src/Tools/BuildActionTelemetryTable/CodeActionDescriptions.cs @@ -186,7 +186,6 @@ internal static class CodeActionDescriptions { "Microsoft.CodeAnalysis.CSharp.PopulateSwitch.CSharpPopulateSwitchExpressionCodeFixProvider", "Populate Switch: Expression" }, { "Microsoft.CodeAnalysis.CSharp.PopulateSwitch.CSharpPopulateSwitchStatementCodeFixProvider", "Populate Switch: Statement" }, { "Microsoft.CodeAnalysis.CSharp.QualifyMemberAccess.CSharpQualifyMemberAccessCodeFixProvider", "Qualify Member Access" }, - { "Microsoft.CodeAnalysis.CSharp.RemoveAsyncModifier.CSharpRemoveAsyncModifierCodeFixProvider", "Remove Async Modifier" }, { "Microsoft.CodeAnalysis.CSharp.RemoveConfusingSuppression.CSharpRemoveConfusingSuppressionCodeFixProvider", "Remove Confusing Suppression" }, { "Microsoft.CodeAnalysis.CSharp.RemoveInKeyword.RemoveInKeywordCodeFixProvider", "Remove In Keyword" }, { "Microsoft.CodeAnalysis.CSharp.RemoveUnnecessaryCast.CSharpRemoveUnnecessaryCastCodeFixProvider", "Remove Unnecessary Cast" }, diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Utilities/IAsyncEnumerableExtensions.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Utilities/IAsyncEnumerableExtensions.cs index 31cf47d93254c..193a68266be3d 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Utilities/IAsyncEnumerableExtensions.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Utilities/IAsyncEnumerableExtensions.cs @@ -16,6 +16,7 @@ internal static class AsyncEnumerable { public static readonly IAsyncEnumerable Empty = GetEmptyAsync(); + // Remove after .NET 10, https://github.com/dotnet/roslyn/issues/80198 #pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously private static async IAsyncEnumerable GetEmptyAsync() { @@ -24,6 +25,7 @@ private static async IAsyncEnumerable GetEmptyAsync() #pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously } + // Remove after .NET 10, https://github.com/dotnet/roslyn/issues/80198 #pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously internal static async IAsyncEnumerable SingletonAsync(T value) {