bugGNU Octave - Bugs: bug #60791, classdef subsasgn / subsref called...

 
 

bug #60791: classdef subsasgn / subsref called incorrectly

Submitter:  Ray Zimmerman <rdzman>
Submitted:  Thu 17 Jun 2021 05:37:07 PM UTC
 
Category:  Interpreter Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  None Assigned to:  None
Originator Name:  Open/Closed:  * Open
Release:  * 6.2.0 Operating System:  * Any
* Mandatory Fields

Add a New Comment (Rich Markup)
   

Comment Type & Canned Response:
       

 

Sun 26 Dec 2021 10:31:01 AM UTC, comment #2: 

I had a look at the issue and I found the cause. In the sequence of instructions:

T1 = rdz_table(1);
cls = @rdz_table;
T2 = rdz_table(2);

when executing

cls = @rdz_table;

the definition of the class constructor is not found, although it should, and the class is loaded again. This causes problems later, because now there are two rdz_table classes loaded, and octave thinks they are different.

Why is the class constructor not found? When executing

T1 = rdz_table(1);

the class constructor is loaded from the file, and the octave_value representing the constructor is stored in the class_constructors member of a fnc_info_rep object (method fcn_info::fcn_info_rep::load_class_constructor in file fcn-info.cc). It is also temporarily stored in the function_on_path member of the same fnc_info_rep object, but then the function_on_path is restored to its previous value.

I don't understand why function_on_path is restored. I tried to eliminate the restoring, and I found that it eliminates the problem, while also passing all the tests. I attach the proposed patch.

(file #52570)

Fernando <tutissanalio>
Thu 17 Jun 2021 07:47:41 PM UTC, comment #1: 

FWIW, I also just noticed that if you create a handle to the constructor before calling it the first time, that also resolves the problem.

Ray Zimmerman <rdzman>
Thu 17 Jun 2021 05:37:07 PM UTC, original submission:  

The subsasgn and subsref methods of a classdef object can be called from within methods of the class by saving a handle to the constructor.

The following example should never call the class's subsasgn method, but it does call it on the second call to the constructor.

classdef rdz_table
    properties
        p
    end
    methods
        function obj = rdz_table(val)
            obj.p = val;
        end
        function obj = subsasgn(obj, s, b)
            disp('yikes')
        end
    end
end

disp('1')
T1 = rdz_table(1);
cls = @rdz_table;
disp('2')
T2 = rdz_table(2);
disp('3')

Commenting out the line that assigns cls makes the problem go away. I believe it also affects subsref, since the following results in a mistaken call to subsasgn which subsequently mistakenly calls subsref resulting in a recursion limit.

pkg load tablicious
T1 = table(1);
cls = @table;
T2 = table(2);

This example above works fine on 5.2.0. FYI, I've only tested this on macOS, but I suspect it applies to all OSs.

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 #52570:  bug60791.patch added by tutissanalio (1KiB - text/x-patch)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by tutissanalio (Updated the item)
  • -email is unavailable- added by tutissanalio
  • -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 project members can vote.

     

     

     

     

    Follow 2 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2021-12-26 tutissanalio Attached File- Added bug60791.patch, #52570
    2021-12-21 tutissanalio Carbon-Copy- Added tutissanalio

    Back to the top


    Powered by Savane 3.9