Reporter | Alexander Shvedov (shvedov) |
---|---|
Created | Apr 6, 2012 3:24:22 AM |
Updated | Apr 6, 2012 3:26:34 AM |
Priority | Major |
Type | Bug |
Fix versions | No Fix versions |
State | Submitted |
Assignee | Dmitry Ivanov (daivanov) |
Subsystem | Refactoring |
Affected versions | 7.0 Preview |
Fixed in build | No Fixed in build |
Module Module1 Sub Main() Dim x = 1 Dim a = New With {Key .Foo = 0} Dim b = New With {.Boo = 0} Foo(x) Foo(123) Foo(a.Foo) Foo((a.Foo)) Foo(b.Boo) End Sub Sub Foo(ByRef x As Integer) x = x + 1 End Sub End Module
Result:
Module Module1 Sub Main() Dim x = 1 Dim a = New With {Key .Foo = 0} Dim b = New With {.Boo = 0} x = Foo() 123 = Foo() a.Foo = Foo() (a.Foo) = Foo() b.Boo = Foo() End Sub Function Foo() As Integer Dim x As Integer x = x + 1 Return x End Function End Module
VB.NET creates temporary variable when passing non-variable expressions as ByRef parameters. Correct transformation will be:
Module Module1 Sub Main() Dim x = 1 Dim a = New With {Key .Foo = 0} Dim b = New With {.Boo = 0} ' passing original value x = Foo(x) ' nothing is changed, since mutation of ByRef-parameter ' are not visible outside of Foo calls for the usages below: Foo(123) Foo(a.Foo) Foo((a.Foo)) ' VB.NET special case for properties: b.Boo = Foo(b.Boo) End Sub Function Foo(x As Integer) As Integer ' ByVal parameter x = x + 1 Return x End Function End Module