dotnet/roslyn

VB displays wrong error when [Await] doesn't correspond to a valid routine

Open

#7.593 geöffnet am 18. Dez. 2015

Auf GitHub ansehen
 (8 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)C# (4.257 Forks)batch import
Area-CompilersBugConcept-Diagnostic Clarityhelp wanted

Repository-Metriken

Stars
 (20.414 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 6T 17h) (256 gemergte PRs in 30 T)

Beschreibung

I was trying the VB.NET version of a C# issue (that does seem to be specific to LinqPad) and found an erroneous error message.

The code below should say something like "BC30451 'Await' is not declared. It may be inaccessible due to its protection level.", but in fact says "BC37058 'Await' can only be used within an Async method. Consider marking this method with the 'Async' modifier and changing its return type to 'Task'." and the VS2015 IDE (update 1) even suggests a "potential fix" of putting another async next to the one it faithfully retains!

Note that if you uncomment out the definition of an [Await] routine, the code compiles and runs as expected (calling [Await] only once).

Module Module1

Async Sub AsyncMain()
    Dim i = Task.FromResult(1), j = Task.FromResult(2), k = Task.FromResult(3)

    System.Console.WriteLine([Await](i) + Await (j) + Await (k))

End Sub

Sub Main()
    AsyncMain()
    If Debugger.IsAttached Then _
        Console.ReadLine()
End Sub

'Function [Await](I As Task(Of Integer)) As Integer
'    Dim r = I.GetAwaiter.GetResult
'    Console.WriteLine($"Await called for {r}")
'    Return r
'End Function
End Module

Contributor Guide