Skip to content

Indexer properties with optional parameters + parentheses: undocumented breaking change? #17045

@controlflow

Description

@controlflow

VB.NET code with indexer properies with optional parameter:

<System.Runtime.InteropServices.ComImport>
Public Class VBClass
    Public ReadOnly Property Prop(Optional ByVal i As Integer = 0) As VBClassWithIndexer
        Get
            Return New VBClassWithIndexer()
        End Get
    End Property
End Class

Public Class VBClassWithIndexer
    Public ReadOnly Default Property Prop(ByVal s As String) As Integer
        Get
            Return 0
        End Get
    End Property
End Class

C# 5.0 compiler allows using parentheses to reference indexer property without supplying arguments:

class C {
  public void Foo(VBClass c) {
    int i1 = c.Prop[""]; // wrong argument type, int expected
    int i2 = (c.Prop)[""]; // OK, [""] is invoked over 'VBClassWithIndexer' type
  }
}

While C# 6.0 compiler always ignores parentheses:

class C {
  public void Foo(VBClass c) {
    int i1 = c.Prop[""]; // wrong argument type, int expected
    int i2 = (c.Prop)[""]; // wrong argument type, int expected
  }
}

I couldn't find anything like this in the list of documented breaking changes in Roslyn (#7278).
Is this a breaking change or a bug?

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions