Warn when using <Out> without ByRef
- Dominant language
- No language data
- Stars
- 328
- Forks
- 71
- PR merge metrics
- No merged PRs in 30d
Description
Since VB 9, using `ByVal` is no longer mandatory, making method declaration syntax quite a bit cleaner. For `ByRef`, a keyword is still required, and unlike with C#, VB doesn't have an out-specific keyword. Instead, you need to use _both_ `ByRef` _and_ apply the `OutAttribute`, for example:
```vb
Private Function TryGetValue(obj As Object, ByRef result as Integer) As Boolean
End Function
```
This makes it easy to introduce a bug* that doesn't become apparent until runtime:
```vb
Private Function TryGetValue(obj As Object, result as Integer) As Boolean
End Function
```
This code looks fine at first glance, But the `` attribute doesn't actually do anything meaningful (best as I can tell), because `result` is actually implicitly `ByVal` now, not `ByRef`.
Thus, I propose that the compiler annotate this as a warning:
>`OutAttribute` used on `ByVal` method parameter. Consider using `ByRef`.
*) Well, this has embarrassingly happened to me, anyway.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.