mirror of
https://github.com/icsharpcode/ILSpy.git
synced 2026-10-12 02:15:58 +00:00
Making a conversion implicit by unwrapping it hands the operand to a different target type, and a default literal takes its value from that type: "S? x = new S?(default)" holds a value, while "S? x = default" is null. Unwrapping the nullable constructor around a shortened literal therefore turned "S? x = default(S)" into a null nullable. The literal is spelled out again whenever unwrapping moves it to a type other than the one it was shortened from. Converting a using resource to the declared variable type is unconditional now (except when the declaration says "var", which supplies no type): the declaration always spells the type out, so any conversion to it may stay implicit, which is also what shortens default(T) there. Assisted-by: Claude:claude-opus-5[1m]:Claude Code
65 lines
1.3 KiB
C#
65 lines
1.3 KiB
C#
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)
|
|
{
|
|
Use(asyncDisposableStruct);
|
|
}
|
|
}
|
|
|
|
public static async void TestAsyncUsingNullableStruct()
|
|
{
|
|
await using (AsyncDisposableStruct? asyncDisposableStruct = default(AsyncDisposableStruct))
|
|
{
|
|
Use(asyncDisposableStruct);
|
|
}
|
|
}
|
|
|
|
private static void Use(IAsyncDisposable test)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
}
|
|
}
|