Skip to content

Warn when using <Out> without ByRef #328

Open
@chucker

Description

@chucker

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:

Private Function TryGetValue(obj As Object, <Out> ByRef result as Integer) As Boolean

End Function

This makes it easy to introduce a bug* that doesn't become apparent until runtime:

Private Function TryGetValue(obj As Object, <Out> result as Integer) As Boolean

End Function

This code looks fine at first glance, But the <Out> 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    LDM ConsideringLDM has reviewed and we think this has merit

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions