Skip to content

Inferred Set parameter type #197

Open
@AnthonyDGreen

Description

@AnthonyDGreen

There's a lot of redundancy in VB expanded property declarations today. If I consider the backing field I need to specify the type three times. I propose that this broken code today:

Property P As T
    Get
    End Get
    Set(value) ' Error, 'value' parameter must have the same type as property.
    End Set
End Property

Now be compiled to infer the type of the value parameter to match the type of the containing property. Combined with #196 this proposal would eliminate the need to refer to the property type three times (and the name twice).

Technically this sorta works today, if you omit the parameter list of the Set entirely, the compiler implicitly defines a parameter named Value (uppercase! blasphemy) of the property type, very similar to how C# properties work:

Property P As T
    Get
        Return _P
    End Get
    Set ' Legal today.
        _P = Value
    End Set
End Property

We could just stop spitting the parameter list on the setter entirely and start coloring the identifier blue and get all the value of this feature. The only thing we'd lose is the explicitness and it might be less discoverable to a first-time user/reader that the parameter exists and has the name Value but I think I lost the ability to make that argument when I proposed #196. Someone else is free to make it, though.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions