bugGNU Octave - Bugs: bug #60280, nested method causes built-in...

 
 

bug #60280: nested method causes built-in function to be seen as a variable

Submitter:  Ray Zimmerman <rdzman>
Submitted:  Tue 23 Mar 2021 08:51:15 PM UTC
   
 
Category:  Interpreter Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Regression
Status:  Fixed Assigned to:  None
Originator Name:  Open/Closed:  * Closed
Release:  * 6.1.0 Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Thu 01 Apr 2021 07:43:30 AM UTC, comment #2: 

I'm not sure which change fixed it, but after the following changes I made for bug #60137 adn bug #60237, the example appears to work properly for me:


octave:1> classA().meth_a().meth_b([]);
ans = 1
'isempty' is a built-in function from the file libinterp/corefcn/data.cc
ans = 1
'isempty' is a built-in function from the file libinterp/corefcn/data.cc


http://hg.savannah.gnu.org/hgweb/octave/rev/0574c36a095e
http://hg.savannah.gnu.org/hgweb/octave/rev/c74ff452e2bb
http://hg.savannah.gnu.org/hgweb/octave/rev/34d06c73b48d

These changesets make changes in public interfaces, which is something that we try to avoid during a stable release series.  OTOH, they are important to make handles to nested and anonymous functions work properly.  And since handles to nested functions were one of the big new features of Octave 6, I'm in favor of making this change in version 6 even if it causes some (small) backward compatibility issues.  These interfaces are not something that typical users (even those who write .oct files) will encounter.

John W. Eaton <jwe>
Group administrator
Fri 26 Mar 2021 06:13:15 PM UTC, comment #1: 

A better title for this issue would be ...

nested method causes built-in function to be seen as a variable

... but I was not able to find a way to edit it.

Ray Zimmerman <rdzman>
Tue 23 Mar 2021 08:51:15 PM UTC, original submission:  

A bug in my code helped uncover some inconsistent behavior between various versions of Octave and Matlab, with a nested method. Octave 5.2 and Matlab are consistent with each other and behave as I would expect, and Octave 6.1 and 6.2 have different behavior (from Matlab and from each other) and end up treating a built-in function as a variable.

If I knew exactly what was causing the issue I suspect I may be able to find a slightly simpler example, but here is what I was able to reduce it to. I use the following classdef (attached) ...

classdef classA < handle
    properties
        prop
    end

    methods
        function obj = meth_a(obj)
            isempty([])
            which('isempty')
            obj.prop = @(x)meth_a1(obj, x);

            function meth_a1(obj, x)
                isempty([])
                which('isempty')
            end
        end

        function obj = meth_b(obj, x)
            obj.prop(x);
        end
    end
end


When I construct the object, then call meth_a followed by meth_b, I get the following results.

Octave 6.2.0

> classA().meth_a().meth_b([]);
ans = 1
'isempty' is a built-in function from the file libinterp/corefcn/data.cc
ans = [](0x0)
'isempty' is a variable


Octave 6.1.0

> classA().meth_a().meth_b([]);
ans = 1
'isempty' is a built-in function from the file libinterp/corefcn/data.cc
ans =

  classA object array with properties:

      prop

'isempty' is a variable


Octave 5.2.0

> classA().meth_a().meth_b([]);
ans = 1
'isempty' is a built-in function from the file libinterp/corefcn/data.cc
ans = 1
'isempty' is a built-in function from the file libinterp/corefcn/data.cc


MATLAB R2021a

>> classA().meth_a().meth_b([]);

ans =

  logical

   1

built-in (/Applications/-math/MATLAB_R2021a.app/toolbox/matlab/elmat/isempty)

ans =

  logical

   1

built-in (/Applications/-math/MATLAB_R2021a.app/toolbox/matlab/elmat/isempty)


Ray Zimmerman <rdzman>

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #51124:  classA.m added by rdzman (421B - application/octet-stream)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by rik5 (Updated the item)
  • -email is unavailable- added by jwe (Posted a comment)
  • -email is unavailable- added by siko1056 (Updated the item)
  • -email is unavailable- added by rdzman (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 5 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2021-04-06 rik5 StatusReady For Test Fixed
        Open/ClosedOpen Closed
    2021-04-01 jwe StatusNone Ready For Test
    2021-03-27 siko1056 Summarynested method redefines built-in function nested method causes built-in function to be seen as a variable
    2021-03-23 rdzman Attached File- Added classA.m, #51124

    Back to the top

    Powered by Savane 3.13-4b48.
    Corresponding source code