dotnet/roslyn

VB editor doesn't highlight syntax errors in lambdas

オープン

#42,857 opened on 2020/03/27

 (10 件のコメント) (0 件のリアクション) (0 人の担当者)C# (4,257 件のフォーク)batch import
Area-CompilersConcept-Diagnostic Clarityhelp wanted

Repository metrics

Stars
 (20,414 個のスター)
PR merge metrics
 (平均マージ 6d 17h) (30d で 256 merged PRs)

説明

In this code:

Module Program
    Sub Main(args As String())
        Foo(Function() 3,
                Sub(x)
                    Dim x = Function(x) x + 3
                End Sub
        )
    End Sub

    Sub Foo(a As Integer, b As Integer)
             ' Do something
    End Sub

    Sub Foo(a As Func(Of Integer), b As Action(Of Integer))
             ' Do something
    End Sub
End Module

The editor puts a red line under Foo in the third line Foo(Function() 3, saying there is an overload resolution error (which is not true), and doesn't highlight the real errors involving declaring a local variable x and a param x inside the Sub(x) lambda sub that has a param x. These errors are reported in one long message, which may be the reason that the editor can't realize them.

Overload resolution failed because no accessible 'Foo' can be called with these arguments: 'Public Sub Foo(a As Integer, b As Integer)': Lambda expression cannot be converted to 'Integer' because 'Integer' is not a delegate type. 'Public Sub Foo(a As Integer, b As Integer)': Lambda expression cannot be converted to 'Integer' because 'Integer' is not a delegate type. 'Public Sub Foo(a As Func(Of Integer), b As Action(Of Integer))': Lambda parameter 'x' hides a variable in an enclosing block, a previously defined range variable, or an implicitly declared variable in a query expression. 'Public Sub Foo(a As Func(Of Integer), b As Action(Of Integer))': Variable 'x' is already declared as a parameter of this or an enclosing lambda expression. 'Public Sub Foo(a As Func(Of Integer), b As Action(Of Integer))': Variable declaration without an 'As' clause; type of Object assumed. 'Public Sub Foo(a As Func(Of Integer), b As Action(Of Integer))': Operands of type Object used for operator '+'; runtime errors could occur.

コントリビューターガイド