Bug 88442 - Global of struct type behave as local variables
Summary: Global of struct type behave as local variables
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: BASIC (show other bugs)
Version:
(earliest affected)
Inherited From OOo
Hardware: x86-64 (AMD64) All
: high major
Assignee: John
URL:
Whiteboard: target:7.2.0
Keywords:
Depends on:
Blocks: 88092
  Show dependency treegraph
 
Reported: 2015-01-15 06:40 UTC by Lionel Elie Mamane
Modified: 2021-03-30 21:33 UTC (History)
10 users (show)

See Also:
Crash report or crash signature:
Regression By:


Attachments
reproduction example (12.16 KB, application/vnd.oasis.opendocument.text)
2015-01-15 06:40 UTC, Lionel Elie Mamane
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Lionel Elie Mamane 2015-01-15 06:40:37 UTC
Created attachment 112267 [details]
reproduction example

+++ This bug was initially created as a clone of Bug #88092 +++

Reproduction instructions:

1. Open attached document, allowing macros to run.

2. Click "Set Struct" button. Click "OK" on the message boxes appearing.

3. Click "Set Show Struct" button.

Actual behaviour:

  In execution of doShow from the button event (that is, after doSet has
  finished executing), aStr keeps the value assigned to it by doSet,
  but aDate is reset to default (all zeros) value.

Expected behaviour:

  Since aDate is a global, it should keep the value that was assigned
  to it by doSet.


The same can be observed by going in the Basic IDE and running (F5 or the toolbar button) the macros from there.
Comment 1 Buovjaga 2015-01-17 13:17:10 UTC
Repro on Win & Linux.

Changed component to BASIC, I hope it's ok.

Win 7 Pro 64-bit Version: 4.5.0.0.alpha0+
Build ID: 5f6bdce0c0ac687f418821ce328f2987bf340cda
TinderBox: Win-x86@62-TDF, Branch:MASTER, Time: 2015-01-17_01:06:46

Ubuntu 14.10 64-bit
LibreOffice 3.3.0 
OOO330m19 (Build:6)
tag libreoffice-3.3.0.4
Comment 2 QA Administrators 2016-02-21 08:35:50 UTC Comment hidden (obsolete)
Comment 3 QA Administrators 2017-03-06 15:22:16 UTC Comment hidden (obsolete)
Comment 4 QA Administrators 2019-12-03 14:30:00 UTC Comment hidden (obsolete)
Comment 5 John 2021-03-03 16:05:59 UTC
It's worth noting that this is an issue with the "as new" construct. Changing the example macro to use:

Global aDate        as Object

and in doSet

Set aDate = new "com.sun.star.util.Date"

before setting the values and for safety, 

	if not isNULL(aDate) THEN

in doShow


...

And now aDate can hold its value. There's something about the "as new" construct that causes it to get re-initialized to a new object when run the next time.I'm not certain, but I believe this to be incorrect behavior.
Comment 6 Commit Notification 2021-03-21 20:55:32 UTC
John committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/b80069e133d30e80e50a792b2bc1d0c2f9a31bfa

tdf#88442 SBasic: Don't double-initialize a Global ... As New ...

It will be available in 7.2.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 7 Xisco Faulí 2021-03-30 11:03:42 UTC
A polite ping to John:
Is this bug fixed? if so, could you please close it as RESOLVED FIXED ?
Otherwise, Could you please explain what's missing?
Thanks