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
18.97k stars 4.03k forks source link

VB DIM: Misleading accessibility in an error message about an attempt to access inaccessible event declared in an interface #35948

Closed AlekseyTs closed 5 years ago

AlekseyTs commented 5 years ago
        <Fact>
        Public Sub EventImplementation_27()

            Dim csSource =
"
public interface I1
{
    internal static event System.Action P1;
}
"
            Dim csCompiation = GetCSharpCompiation(csSource).EmitToImageReference()

            Dim source1 =
<compilation>
    <file name="c.vb"><![CDATA[
Public Class C
    Shared Sub Main()
        AddHandler I1.P1, Nothing
        RemoveHandler I1.P1, Nothing
    End Sub
End Class
]]></file>
</compilation>

            Dim comp1 = CreateCompilation(source1, targetFramework:=TargetFramework.NetStandardLatest, references:={csCompiation})
            comp1.AssertTheseDiagnostics(
<error>
BC30456: 'P1' is not a member of 'I1'.
        AddHandler I1.P1, Nothing
                   ~~~~~
BC30456: 'P1' is not a member of 'I1'.
        RemoveHandler I1.P1, Nothing
                      ~~~~~
</error>)

            Dim comp2 = CreateCompilation(source1, targetFramework:=TargetFramework.NetStandardLatest, references:={csCompiation}, options:=TestOptions.DebugDll.WithMetadataImportOptions(MetadataImportOptions.All))
            comp2.AssertTheseDiagnostics(
<error>
BC30389: 'I1.P1' is not accessible in this context because it is 'Private'.
        AddHandler I1.P1, Nothing
                   ~~~~~
BC30389: 'I1.P1' is not accessible in this context because it is 'Private'.
        RemoveHandler I1.P1, Nothing
                      ~~~~~
</error>)
        End Sub

Observed:

BC30389: 'I1.P1' is not accessible in this context because it is 'Private'.

Expected:

BC30389: 'I1.P1' is not accessible in this context because it is 'Friend'.
AlekseyTs commented 5 years ago

Here is another scenario:

        <Fact>
        <WorkItem(35948, "https://github.com/dotnet/roslyn/issues/35948")>
        Public Sub EventImplementation_36()

            Dim csSource =
"
public interface I1
{
    private protected static event System.Action P1;
}
"
            Dim csCompiation = GetCSharpCompiation(csSource).EmitToImageReference()

            Dim source1 =
<compilation>
    <file name="c.vb"><![CDATA[
Public Class C
    Implements I1
    Shared Sub Main()
        AddHandler I1.P1, Nothing
        RemoveHandler I1.P1, Nothing
    End Sub
End Class
]]></file>
</compilation>

            Dim comp1 = CreateCompilation(source1, targetFramework:=TargetFramework.NetStandardLatest, references:={csCompiation})
            comp1.AssertTheseDiagnostics(
<error>
BC30389: 'I1.P1' is not accessible in this context because it is 'Private Protected'.
        AddHandler I1.P1, Nothing
                   ~~~~~
BC30389: 'I1.P1' is not accessible in this context because it is 'Private Protected'.
        RemoveHandler I1.P1, Nothing
                      ~~~~~
</error>)

            Dim comp2 = CreateCompilation(source1, targetFramework:=TargetFramework.NetStandardLatest, references:={csCompiation}, options:=TestOptions.DebugDll.WithMetadataImportOptions(MetadataImportOptions.All))
            comp2.AssertTheseDiagnostics(
<error>
BC30389: 'I1.P1' is not accessible in this context because it is 'Private'.
        AddHandler I1.P1, Nothing
                   ~~~~~
BC30389: 'I1.P1' is not accessible in this context because it is 'Private'.
        RemoveHandler I1.P1, Nothing
                      ~~~~~
</error>)
        End Sub

Observed:

BC30389: 'I1.P1' is not accessible in this context because it is 'Private'.

Expected:

BC30389: 'I1.P1' is not accessible in this context because it is 'Private Protected'.