https://bugs.documentfoundation.org/show_bug.cgi?id=150727

            Bug ID: 150727
           Summary: A reference passed as parameter gets a new target
           Product: LibreOffice
           Version: 7.3.5.2 release
          Hardware: x86-64 (AMD64)
                OS: Linux (All)
            Status: UNCONFIRMED
          Severity: minor
          Priority: medium
         Component: BASIC
          Assignee: [email protected]
          Reporter: [email protected]

Try the following code:

```
Sub Main()
        Dim x As String
        x = "foo"         ' (1)
        Aux(x)            ' (2a)
        MsgBox x          ' ==> "bar", expected "foo"
End Sub

Sub Aux(y As String)      ' (2b)
        y = "bar"         ' (3)
End Sub
```

What is expected:
(1) `x` is a reference to a string "foo". 
(2a) and (2b) `y` is a **copy** of `x`, that means that both `x` and `y` are
independent references to the string "foo".
(3) `y`, by affectation, refers to a new string "bar".

This is a weird behavior because `Aux` should only get a copy of `x` and the
reference `x` should not be updated to have the new target value "bar".

I have never seen this behavior in any other language. (The closest thing I can
think of is the C preprocessor pitfalls.)

($ uname -a
Linux jferard-Z170XP-SLI 5.15.0-46-generic #49-Ubuntu SMP Thu Aug 4 18:03:25
UTC 2022 x86_64 x86_64 x86_64 GNU/Linux)

Maybe related to: https://bugs.documentfoundation.org/show_bug.cgi?id=145279

-- 
You are receiving this mail because:
You are the assignee for the bug.

Reply via email to