bugGNU Octave - Bugs: bug #57256, Using global variable in nested...

 
 

bug #57256: Using global variable in nested function makes variable disappear in parent function

Submitter:  qx1147 <qx1147>
Submitted:  Mon 18 Nov 2019 01:07:18 PM UTC
   
 
Category:  Interpreter Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Unexpected Error or Warning
Status:  Fixed Assigned to:  None
Originator Name:  Open/Closed:  * Closed
Release:  * 5.1.0 Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Tue 19 Nov 2019 05:04:40 PM UTC, comment #1: 

This problem has been fixed in the development version. The fix
will be available in the next major software release. Thank you
for your bug report.

Rik <rik5>
Group administrator
Mon 18 Nov 2019 01:07:18 PM UTC, original submission:  

Calling the following demo function fails with an "'s' undefined near line 5" error, so calling the nested() function, which accesses the global variable 's' (with or without declaring it "global"), makes the global variable 's' disappear in demo() thereafter. I can bring 's' back, however, with another "global" statement.
The same code works fine in Octave 4.2.1.
 

function demo()
    global s=99
    nested();
#    global s        % needed for making 's' accessible again.
    fprintf('demo(): s=%d.\n', s);

    function nested()
        fprintf('nested(): s=%d.\n', s);
    end
end


Output:

>> demo

nested(): s=99.
error: 's' undefined near line 5 column 32
error: called from
    demo at line 5 column 5


Output with old Octave, or when using the second "global" statement:

>> demo

nested(): s=99.
demo(): s=99.


qx1147 <qx1147>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by qx1147 (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 2 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2019-11-19 rik5 StatusNone Fixed
        Open/ClosedOpen Closed

    Back to the top

    Powered by Savane 3.13-4b48.
    Corresponding source code