Bug 57308 - Basic IDE: watching of variable not working if variable is returning value of function
Summary: Basic IDE: watching of variable not working if variable is returning value of...
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: BASIC (show other bugs)
(earliest affected)
3.4.2 release
Hardware: All All
: medium minor
Assignee: Andreas Heinisch
Depends on:
Blocks: Macro-StarBasic
  Show dependency treegraph
Reported: 2012-11-20 08:37 UTC by sasha.libreoffice
Modified: 2021-10-22 18:19 UTC (History)
4 users (show)

See Also:
Crash report or crash signature:


Note You need to log in before you can comment on or make changes to this bug.
Description sasha.libreoffice 2012-11-20 08:37:24 UTC
Basic IDE problem: If we place variable which returns value from function to Watch window, it not working. Always tells "Out of scope"

Steps to reproduce:
0. Start any LO module, for example, Writer
1. Press Alt-F11, in dialog "LibreOffice Basic Macros" press "New" and then "Ok"
2. In Basic IDE enter something like this:

Sub Main
End Sub
Function MySum (a as Integer, b as Integer)
End Function

3. Place cursor on word MySum and press F7. This variable added to Watch window
4. Place cursor on line where is MySum=0 and press F9. BreakPoint added
5. Place cursor on line where Sub Main and press F5
6. Press F8 several times and see on Watch window
Expected: value of variable MySum is shown
Actually: always "Out of scope"

reproduced in 3.4.2 on Windows XP 32 bit and in 3.6.3 on RFR 17 64 bit

Workaround: create new variable and use it for all calculations, then assign result to returning variable in last line of function
Comment 1 LeMoyne Castle 2012-12-22 05:36:28 UTC
Confirmed with 12/20 build of dev master.  Always <Out of scope>.  The lexical scope of  the function name is file/module scope.  IIRC, some time ago, Noel Power told me that some module scope objects have this issue.  Moved to NEW.

Tested global vars (working) and const items (don't work) with the following: 

global SomeTweak as integer  
const TweakToo = 2

Sub Main
    SomeTweak = 1 
    MsgBox c 
End Sub

public Function MySum (a as Integer, b as Integer)
End Function

I know watching a const isn't very useful but there may be even more BASIC constructs that have this issue of falsely reporting <out of scope> in the Watch Window.
Comment 2 LeMoyne Castle 2013-01-04 17:03:50 UTC
More generally, want to be able to watch expressions that include functions, in scope vars and values from the object model.  For example the following should show true, false, <type error>?, in addition to <out of scope> where appropriate: oSheet.Cells(r,c).value = 3 . 

Will look at this while working on 57307.
Comment 3 QA Administrators 2015-01-05 17:52:32 UTC Comment hidden (obsolete)
Comment 4 Buovjaga 2015-01-29 10:18:03 UTC

Win 7 Pro 64-bit Version:
Build ID: 784d069cc1d9f1d6e6a4e543a278376ab483d1eb
TinderBox: Win-x86@62-TDF, Branch:MASTER, Time: 2015-01-25_23:07:36
Comment 5 QA Administrators 2016-02-21 08:38:05 UTC Comment hidden (obsolete)
Comment 6 QA Administrators 2017-03-06 16:08:25 UTC Comment hidden (obsolete)
Comment 8 himajin100000 2019-08-24 16:35:42 UTC Comment hidden (obsolete)
Comment 9 himajin100000 2019-08-24 16:55:51 UTC
' As Subroutine name is added to the public variable list, the following code runs without errors.

Option Explicit

Sub Recursive() As Integer

End Sub 

Sub Main()
	Recursive = 1
End Sub
Comment 10 himajin100000 2019-08-29 21:41:22 UTC
Hmmm, if the variable with another function name is used, the function with that named seems to be called.
Comment 11 Andreas Heinisch 2021-04-07 17:25:09 UTC
The problem is that if you watch a method/variable, LO tries to retrieve the value of the that variable, which is not yet fully computed. Hence, the watch window always shows out of scope.

However, I tried to add:
else if (SbxMethod const* pMeth = dynamic_cast<SbxMethod*>(pSBX))
    const SbxValues& pVals = pMeth->GetValues_Impl();
    double test = pVals.nDouble;
    aTypeStr += getBasicTypeName(pMeth->GetType());

but the test value in this example are always empty.
Comment 12 Andreas Heinisch 2021-10-22 18:19:41 UTC
Proposed patch: https://gerrit.libreoffice.org/c/core/+/124075