bugGNU Octave - Bugs: bug #67417, Assignment shadows everything when...

 
 

bug #67417: Assignment shadows everything when script is called from nested function

Submitter:  None
Submitted:  Mon 11 Aug 2025 10:14:16 AM UTC
   
 
Category:  Interpreter Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  None Assigned to:  None
Originator Name:  Alexis THIBAULT Originator Email:  -email is unavailable-
Open/Closed:  * Open Release:  * 9.4.0
Operating System:  * Mac OS Fixed Release:  None
Planned Release:  None
* Mandatory Fields

Post a Comment

Add a New Comment Rich Markup
   

Discussion

Thu 14 Aug 2025 05:39:25 PM UTC, comment #4: 

When the script is executed in the context of a nested function it seems that all(?) symbols in the script appear to share the same storage location.  So given the following script and function:



% myscript.m
foo = 13
bar = 42
foo
bar
rand
svd
x



% myfun.m
function myfun()
  myfun2()
  function myfun2()
    x = 10
    myscript
  end
end


I see the following behavior:


octave:1> myfun
x = 10
foo = 13
bar = 42
foo = 42
bar = 42
rand = 42
svd = 42
x = 10
error: rand(10): out of bound 1 (dimensions are 1x1) (note: variable 'rand' shadows function)
error: called from
    myscript at line 8 column 1
    myfun>myfun2 at line 5 column 5
    myfun at line 2 column 3


I'll see if I can come up with a fix.

John W. Eaton <jwe>
Group administrator
Thu 14 Aug 2025 03:04:34 AM UTC, comment #3: 

Reproducible with a clean octave 11 version (compiled yesterday) and using the Octave default branch (I work on linux/ubuntu).


Note that when the byte code virtual machine is active (I work in general with the bytecode-interpreter mercurial branch), the minimum example works flawlessly and causes no error. Disabling the VM machine (_vm_enable(0)) reproduces the error. So clearly this is an issue with the default octave interpreter.


octave:1> __vm_enable__(0)
octave:2> myfun
error: disp(42): out of bound 1 (dimensions are 1x1) (note: variable 'disp' shadows function)
error: called from
    myscript at line 4 column 1
    myfun>myfun2 at line 5 column 5
    myfun at line 2 column 3



octave:1> __vm_enable__(1)
octave:2> myfun
42



Hendrik K <koerhen>
Mon 11 Aug 2025 06:31:30 PM UTC, comment #2: 

I can reproduce this with Octave 11. I modified slightly the files:

$ cat myfun.m
function myfun()
  myfun2()

  function myfun2()
    myscript
  end
end
$ cat myscript.m
1
foo = 42
disp
disp(foo)


And I see:

octave:1> myfun
ans = 1
foo = 42
disp = 42
error: disp(42): out of bound 1 (dimensions are 1x1) (note: variable 'disp' shadows function)
error: called from
    myscript at line 4 column 1
    myfun>myfun2 at line 5 column 5
    myfun at line 2 column 3


Dmitri.
--

Dmitri A. Sergatskov <dasergatskov>
Mon 11 Aug 2025 05:45:34 PM UTC, comment #1: 

Works on Octave 11:

octave:1> myfun
42


Anonymous
Mon 11 Aug 2025 10:14:16 AM UTC, original submission:  

Hello,

While trying to wrap legacy scripts into functions, I stumbled upon a strange behavior of octave: when a script is called from a nested function, any assignment results in shadowing every identifier including core functions. Thus the script fails unexpectedly, some lines after the faulty assignment, whenever a function call is misinterpreted as cell indexing.

Here is a minimal working example:


--- myscript.m
foo = 42;
disp(foo);

--- myfun.m
function myfun()
  myfun2();

  function myfun2()
    myscript
  end
end

---
octave:1> myfun
error: disp(42): out of bound 1 (dimensions are 1x1) (note: variable 'disp' shadows function)
error: called from
    myscript at line 2 column 1
    myfun>myfun2 at line 5 column 5
    myfun at line 2 column 3



Anonymous

 

Attached Files

This item currently has no attached files.

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

Attach Files:
   
   
Comment:
   

 

Dependencies

This item does not depend on any other items.

No items depend on this one.

 

Mail Notification Carbon-Copy List

Carbon-Copy List
  • -email is unavailable- added by jwe (Posted a comment)
  • -email is unavailable- added by koerhen (Posted a comment)
  • -email is unavailable- added by dasergatskov (Posted a comment)
  • -email is unavailable- added by None (Submitted the item)
  •  

    Votes

    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.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

    History

    No changes have been made to this item

    Back to the top

    Powered by Savane 3.16-a7ba.
    Corresponding source code