bugGNU Octave - Bugs: bug #53579, Change in global handling for...


bug #53579: Change in global handling for variable in global and passed as argument

Submitted by:  Michael Godfrey <godfrey>
Submitted on:  Sat 07 Apr 2018 03:21:27 AM UTC  
Category:  Interpreter Severity:  3 - Normal
Priority:  7 - High Item Group:  Regression
Status:  Fixed Assigned to:  None
Originator Name:  godfrey Open/Closed:  Closed
Release:  dev Operating System:  GNU/Linux

Add a New Comment (Rich Markup)

You are not logged in

Please log in, so followups can be emailed to you.


Wed 11 Apr 2018 05:25:06 AM UTC, comment #3: 

Works for me. Both stable and dev.

Michael Godfrey <godfrey>
Project Member
Wed 11 Apr 2018 04:30:10 AM UTC, comment #2: 

I pushed the following changeset, including a test:


Please let me know whether the new test is correct.

John W. Eaton <jwe>
Project Administrator
Sat 07 Apr 2018 07:06:43 PM UTC, comment #1: 

The new behavior is in the current stable 4.3.0+ version.
This means that the new release is incompatible with
the current 4.2.2 and with Matlab.

It may be confusing for users of the new release to just
report: "error: 'aa' undefined near line 5 column 3..."
where previously the variable was still defined.

It might be best to detect this case (variable in global
list and passed as argument) and report it as a warning.
This choice is compatible with the current Matlab
which behaves like 4.2.2, but also produces a confusing

Michael Godfrey <godfrey>
Project Member
Sat 07 Apr 2018 03:21:27 AM UTC, original submission:  

It would seem that the handling of the case below in the
current dev is appropriate, but it conflicts with 4.2.2 and
previous versions. The error occurs if a variable in declared
global and used in a function argument list. Below shows
Matlab, 4.2.2, ad dev results. I do not fully understand
the Matlab error message...

I think that the handling in dev is a good choice, but the
error message should be made clearer and the incompatibility
with previous Octaves should be noted. The diagnostic could
be: passing a variable which is declared global as an argument
is not allowed...

The script top.m is:
global aa bb
  xx =1 ;
  aa = 1;
  sub1(aa, xx);
sub1.m is:
function sub1 (aa, bb)
  global aa bb
  aa = 1;

Results for Matlab, 4.2.2, and dev 4.5.0+ are:

                                      < M A T L A B (R) >
                            Copyright 1984-2017 The MathWorks, Inc.
                             R2017b ( 64-bit (glnxa64)
                                       September 14, 2017

To get started, type one of these: helpwin, helpdesk, or demo.
For product information, visit www.mathworks.com.

>> ls
sub1.m        top.m

>> top
Warning: The value of local variables may have been changed to match the globals.  Future versions
of MATLAB will require that you declare a variable to be global before you use that variable.
> In sub1 (line 2)
  In top (line 4)
Warning: The value of local variables may have been changed to match the globals.  Future versions
of MATLAB will require that you declare a variable to be global before you use that variable.
> In sub1 (line 2)
  In top (line 4)

aa =


Results for
GNU Octave, version 4.2.2
Copyright (C) 2018 John W. Eaton and others.
This is free software; see the source code for copying conditions.
FITNESS FOR A PARTICULAR PURPOSE.  For details, type 'warranty'.

Octave was configured for "x86_64-redhat-linux-gnu".

Additional information about Octave is available at http://www.octave.org.

Please contribute if you find this software useful.
For more information, visit http://www.octave.org/get-involved.html

Read http://www.octave.org/bugs.html to learn how to submit bug reports.
For information about changes from previous versions, type 'news'.

octave:1> top
aa =  1
octave:2> quit

Results for dev:
[godfrey@pbdsl4 global_change]$ oct
octave:1> version
ans = 4.5.0+
octave:2> top
error: 'aa' undefined near line 5 column 3
error: called from
    top at line 5 column 3

Michael Godfrey <godfrey>
Project Member


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

Attach Files:

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 jwe (Posted a comment)
  • -email is unavailable- added by godfrey (Submitted the item)

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.




    Follow 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2018-04-11 jwe StatusReady For Test => Fixed
        Open/ClosedOpen => Closed
    2018-04-11 jwe StatusNone => Ready For Test
    2018-04-07 godfrey Priority5 - Normal => 7 - High

    Back to the top

    Powered by Savane 3.5