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.96k stars 4.02k forks source link

List patterns: duplicate errors when no suitable indexers #59529

Open sa-exe opened 2 years ago

sa-exe commented 2 years ago

Version Used: main (27 Jan 2022, https://github.com/dotnet/roslyn/commit/3b32fc36ec4c2a81457d90f965c89c5b6fc37082)

Steps to Reproduce:

using System;

_ = new Inaccessible() is [..var x];

public struct Inaccessible
{
    public int Length => 42;
    // this[Index] is missing
    // this[Range] is not accessible
    private Inaccessible this[Range r] => default;
}

Expected Behavior: two errors: one refers to the lack of this[Index] and the other says this[Range] is inaccessible. e.g. something like this, though I'm not sure the first error is clear enough:

error CS0021: Cannot apply indexing with [] to an expression of type 'Inaccessible'
error CS0122: 'Inaccessible.this[Range]' is inaccessible due to its protection level

Actual Behavior: both error messages refer to this[Range]

error CS0122: 'Inaccessible.this[Range]' is inaccessible due to its protection level
error CS0122: 'Inaccessible.this[Range]' is inaccessible due to its protection level

https://sharplab.io/#v2:EYLgtghglgdgNAExAagD4AEBMBGAsAKAIH0ACAXhJgFMB3EgSRggGNmqBndqYAGyoAoAlCSjsSAbQB0kgG4QATiQAeAXQDcBAugDMJdgBd5AV2b6GTVhy68qBAN4ESTkjpEwzAGSowA5voAW5AB8JAAsmBr4ziQADvJQcvpU5ixsnNx8JAGi4gBKEL7J8irBJAhUAGYQRjz6kQC+QA==

jcouv commented 2 years ago

FYI @alrz