dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
19.13k stars 4.04k forks source link

VB Value Task #72241

Closed CoolCoderSuper closed 9 months ago

CoolCoderSuper commented 9 months ago

Version Used:

Steps to Reproduce:

Put async modifer on function returning ValueTask

For example when implementing IAsyncDisposeable

Imports System
Imports System.Threading.Tasks
Public Class C
    Implements IAsyncDisposable
    Public Sub M()
    End Sub

    Public Async Function DisposeAsync() As ValueTask Implements IAsyncDisposable.DisposeAsync
        Throw New NotImplementedException()
    End Function
End Class

Diagnostic Id:

BC36945 The 'Async' modifier can only be used on Subs, or on Functions that return Task or Task(Of T).

Expected Behavior: Should be treated like a normal async method. Actual Behavior:

huoyaoyuan commented 9 months ago

VB does not enable creation support for ValueTask. Searching at https://github.com/dotnet/vblang/issues , I can't find any feature request for this either.

jaredpar commented 9 months ago

As @huoyaoyuan noted this behavior is "By Design" as VB does not support Async methods that return ValueTask.

huoyaoyuan commented 9 months ago

I wonder if we can put some effort to bring VB features more parity with corresponding C# feature. Implementation link lowering and specification corners can be borrowed from C#, so the effort should be relatively lower. An example is await in catch and finally.

InteXX commented 7 months ago

@CoolCoderSuper @huoyaoyuan

Anthony Green (former head of the VB.NET team at Microsoft) has been working on something he calls ModVB. With it we'll be able to modify the language to suit our needs—to include this issue.

His blog can be found here:

https://anthonydgreen.net/

You may follow his progress if you wish, and join the discussion, at our Discord community site:

https://discord.com/channels/682603493386747904/1073635946567835798

We hope to see you there!