From 4de2055d6329265808ed360739579ac3b89bc272 Mon Sep 17 00:00:00 2001 From: Julien Couvreur Date: Tue, 19 Mar 2024 10:46:26 -0700 Subject: [PATCH] tweaks --- .../CSharp/Portable/Binder/UsingStatementBinder.cs | 13 +++++++------ .../IOperation/IOperationTests_IUsingStatement.cs | 8 ++++---- .../Semantic/Semantics/UsingDeclarationTests.cs | 5 ++++- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Binder/UsingStatementBinder.cs b/src/Compilers/CSharp/Portable/Binder/UsingStatementBinder.cs index 6d96a6c356c6b..417f9046a406f 100644 --- a/src/Compilers/CSharp/Portable/Binder/UsingStatementBinder.cs +++ b/src/Compilers/CSharp/Portable/Binder/UsingStatementBinder.cs @@ -234,17 +234,16 @@ bool bindDisposable(bool fromExpression, out MethodArgumentInfo? patternDisposeI CompoundUseSiteInfo useSiteInfo = originalBinder.GetNewCompoundUseSiteInfo(diagnostics); Conversion iDisposableConversion = classifyConversion(fromExpression, disposableInterface, ref useSiteInfo); - patternDisposeInfo = null; - awaitableType = null; diagnostics.Add(syntax, useSiteInfo); if (iDisposableConversion.IsImplicit) { - if (hasAwait) - { - awaitableType = originalBinder.Compilation.GetWellKnownType(WellKnownType.System_Threading_Tasks_ValueTask); - } + patternDisposeInfo = null; + + awaitableType = hasAwait + ? originalBinder.Compilation.GetWellKnownType(WellKnownType.System_Threading_Tasks_ValueTask) + : null; return !ReportUseSite(disposableInterface, diagnostics, hasAwait ? awaitKeyword : usingKeyword); } @@ -264,6 +263,8 @@ bool bindDisposable(bool fromExpression, out MethodArgumentInfo? patternDisposeI Error(diagnostics, errorCode, syntax, declarationTypeOpt ?? expressionOpt!.Display); } + patternDisposeInfo = null; + awaitableType = null; return false; } diff --git a/src/Compilers/CSharp/Test/IOperation/IOperation/IOperationTests_IUsingStatement.cs b/src/Compilers/CSharp/Test/IOperation/IOperation/IOperationTests_IUsingStatement.cs index 87bc0c5214ef4..9e9db28ab3a2c 100644 --- a/src/Compilers/CSharp/Test/IOperation/IOperation/IOperationTests_IUsingStatement.cs +++ b/src/Compilers/CSharp/Test/IOperation/IOperation/IOperationTests_IUsingStatement.cs @@ -145,8 +145,8 @@ public async Task M1() }/**/ } - public async System.Threading.Tasks.ValueTask DisposeAsync() - { + public async System.Threading.Tasks.ValueTask DisposeAsync() + { await Task.Yield(); } } @@ -204,8 +204,8 @@ public async Task M1() }/**/ } - async ValueTask IAsyncDisposable.DisposeAsync() - { + async ValueTask IAsyncDisposable.DisposeAsync() + { await Task.Yield(); } } diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/UsingDeclarationTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/UsingDeclarationTests.cs index 7646942ebd539..da09f7cdd28d2 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/UsingDeclarationTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/UsingDeclarationTests.cs @@ -867,7 +867,10 @@ static async Task Main() "; var expected = new[] { - // (8,15): error CS8652: The feature 'using declarations' is not available in C# 7.3. Please use language version 8.0 or greater. + // 0.cs(8,9): error CS8370: Feature 'pattern-based disposal' is not available in C# 7.3. Please use language version 8.0 or greater. + // await using IAsyncDisposable x = null; + Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion7_3, "await using IAsyncDisposable x = null;").WithArguments("pattern-based disposal", "8.0").WithLocation(8, 9), + // 0.cs(8,15): error CS8370: Feature 'using declarations' is not available in C# 7.3. Please use language version 8.0 or greater. // await using IAsyncDisposable x = null; Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion7_3, "using").WithArguments("using declarations", "8.0").WithLocation(8, 15) };