dotnet / dotnet/vblang

Inferred `Set` parameter type

Open
#197 3 comments 3 reactions 1 assignee Claimed by @AnthonyDGreen View on GitHub
Approved-in-Principle Proposal Prototype-Needed
Dominant language
No language data
Stars
328
Forks
71
PR merge metrics
No merged PRs in 30d

Description

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:

``` VB.NET
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:

``` VB.NET
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.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.