[Proposal] Using [] for indexes, ranges, and limiting type ranges
- Dominant language
- No language data
- Stars
- 328
- Forks
- 71
- PR merge metrics
- No merged PRs in 30d
Description
Dealing with Small Basic, I became a fan of using `[]` for indexing collections (`a[0]`), and I want this to be optional in VB.NET besides `()` (`a(0)`).
This will allow us also to use ranges:
`Dim a = [1 To 5] ' a = {1, 2, 3, 4, 5}`
`If x in [1 To 5] Then'
Which is optimized to:
`If x >= 1 AndAlso x <= 5 Then'
And even restrict value types range
```
Dim x as Integer[100 To 1000]`
x = 1001 ' Exception
```
Which will be lowered to
```
Dim x as Integer
Sub Set_[LOCALID]_x(value as integer, )
If 1001 >= 100 AndAlso 1001 <= 1000) Then
x = 1001
else
Throw New OutOfRangeException()
EndIf
End Sub
```
Any assignment to x will be replaced with such checks. If x is paced byref, then we will pass a temp var instead, then do the same check before assigning the temp val to x.
We can do the same for function params, and property setters.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.