zompinc / sync-method-generator

Generates a synchronized version of an async method
MIT License
48 stars 4 forks source link

Fix dropping default ValueTask #49

Closed GerardSmit closed 8 months ago

GerardSmit commented 8 months ago

This PR fixes dropping ValueTask.CompletedTask, default (when the return type is ValueTask) and new ValueTask<T>(...).

ValueTask

Before

ValueTask.CompletedTask

public static ValueTask DoSomethingAsync() { return ValueTask.CompletedTask; }
public static ValueTask DoSomethingAsync() { return ValueTask.CompletedTask; Console.WriteLine(\"123\"); }
public static ValueTask DoSomethingAsync() => ValueTask.CompletedTask;

// -->

public static void DoSomething() { return global::System.Threading.Tasks.ValueTask.CompletedTask; }

Default

public static ValueTask DoSomethingAsync() { return default; }

// -->

public static void DoSomething() { return default; }

New

public static ValueTask DoSomethingAsync() { return new(); }

// -->

public static void DoSomething() { return new(); }

After (PR)

public static ValueTask DoSomethingAsync() { return ValueTask.CompletedTask; }
public static ValueTask DoSomethingAsync() { return ValueTask.CompletedTask; Console.WriteLine(\"123\"); }
public static ValueTask DoSomethingAsync() => ValueTask.CompletedTask;
public static ValueTask DoSomethingAsync() { return default; }
public static ValueTask DoSomethingAsync() { return new(); }

// -->

public static void DoSomething() { }

ValueTask\<T>

Before

public static ValueTask<int> ReturnAsync() => new(1);

// -->

public static int Return() { return new(1); }

After (PR)

public static ValueTask<int> ReturnAsync() => new(1);

// -->

public static int Return() { return 1; }
codecov[bot] commented 8 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Comparison is base (f27382a) 94.23% compared to head (4607909) 94.26%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #49 +/- ## ========================================== + Coverage 94.23% 94.26% +0.02% ========================================== Files 8 8 Lines 902 924 +22 Branches 192 198 +6 ========================================== + Hits 850 871 +21 Misses 24 24 - Partials 28 29 +1 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

virzak commented 8 months ago

Thanks so much. Easy to read and understand. Version 1.3.6.