diff --git a/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj b/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj index 0d2436bf4..ac3e8c51a 100644 --- a/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj +++ b/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj @@ -81,6 +81,7 @@ + diff --git a/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs b/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs index 4a34baaf9..54cb2aae3 100644 --- a/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs +++ b/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs @@ -301,6 +301,12 @@ namespace ICSharpCode.Decompiler.Tests Run(cscOptions: cscOptions); } + [Test] + public void AsyncUsing([ValueSource(nameof(roslynOnlyOptions))] CompilerOptions cscOptions) + { + RunForLibrary(cscOptions: cscOptions); + } + [Test] public void CustomTaskType([ValueSource(nameof(roslynOnlyOptions))] CompilerOptions cscOptions) { diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/AsyncUsing.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/AsyncUsing.cs new file mode 100644 index 000000000..98b3ce07b --- /dev/null +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/AsyncUsing.cs @@ -0,0 +1,60 @@ +using System; +using System.Runtime.InteropServices; +using System.Threading.Tasks; + +namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty +{ + internal class AsyncUsing + { + internal class AsyncDisposableClass : IAsyncDisposable + { + public ValueTask DisposeAsync() + { + throw new NotImplementedException(); + } + } + + [StructLayout(LayoutKind.Sequential, Size = 1)] + internal struct AsyncDisposableStruct : IAsyncDisposable + { + public ValueTask DisposeAsync() + { + throw new NotImplementedException(); + } + } + + public static async void TestAsyncUsing(IAsyncDisposable disposable) + { + await using (disposable) { + Console.WriteLine("Hello"); + } + } + + public static async void TestAsyncUsingClass() + { + await using (AsyncDisposableClass test = new AsyncDisposableClass()) { + Use(test); + } + } + + public static async void TestAsyncUsingStruct() + { + await using (AsyncDisposableStruct asyncDisposableStruct = default(AsyncDisposableStruct)) { + Use(asyncDisposableStruct); + } + } + + public static async void TestAsyncUsingNullableStruct() + { + await using (AsyncDisposableStruct? asyncDisposableStruct = new AsyncDisposableStruct?(default(AsyncDisposableStruct))) { + Use(asyncDisposableStruct); + } + } + + private static void Use(IAsyncDisposable test) + { + throw new NotImplementedException(); + } + + } +} diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InterfaceTests.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InterfaceTests.cs index d26c1fb68..7a7f8799d 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InterfaceTests.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InterfaceTests.cs @@ -16,9 +16,6 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// We can't test this because "error CS8701: Target runtime doesn't support default interface implementation." -#undef CS80 - using System; namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty