bugGNU Octave - Bugs: bug #55887, Edit changes to classdef object...

 
 

bug #55887: Edit changes to classdef object are seen(executed) after saving file and re-initializiing the object

Submitter:  None
Submitted:  Tue 12 Mar 2019 12:01:48 AM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Works For Me Assigned to:  None
Originator Name:  Del Johnson Originator Email:  -email is unavailable-
Open/Closed:  * Closed Release:  * 5.1.0
Operating System:  * Any Fixed Release:  None
Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Tue 14 Jan 2020 08:58:16 PM UTC, comment #10: 

John W. Eaton (thank you for making, distributing, and still leading GNU Octave). To answer your question concerning another bug report, yes there is, this one: https://savannah.gnu.org/bugs/?45893

Louis <louisgag>
Tue 14 Jan 2020 05:11:11 PM UTC, comment #9: 

I think Octave does the reasonable thing in Octave 6.1.  For this code


t1 = testprop ();  # create instance of testprop class with test = 0
%% Modify testprop.m so that property test has value = 2
t2 = testprop ();  # create second instance of testprop class
t1.test
ans = 0
t2.test
ans = 2


In other words, existing objects are left alone but newly created ones use the most up-to-date definition.

But, if you want to see WTF! Matlab behavior, visit https://www.mathworks.com/help/matlab/matlab_oop/modifying-and-reloading-classes.html.

In Matlab, changing the class definition automatically updates all instantiated objects to reflect the new definition.  Thus, if you happen to have the same classname in different directories then changing the path or using 'cd' can completely re-instantiate all of your objects.

Rik <rik5>
Group administrator
Tue 14 Jan 2020 04:46:13 PM UTC, comment #8: 

Rik, was there another bug report about this issue?  If we try to reload the class definition when there are existing objects that expect the previous class definition, that could cause trouble.

John W. Eaton <jwe>
Group administrator
Tue 14 Jan 2020 04:35:51 PM UTC, comment #7: 

Thank you for this solution, it helps a lot.
Curious to see Octave 6.1

Louis <louisgag>
Tue 14 Jan 2020 04:18:17 PM UTC, comment #6: 

For compatibity with Matlab variables need to be removed by "clear classes".  See https://www.mathworks.com/help/matlab/ref/clear.html.

If you don't want to lose variables then use


clear functions


which will clear the class definitions used for new instances, but leave existing class objects and other variables alone.

The behavior in Octave 6.1 which wil be released within the next month is even better.  It detects when the class definition file has changed and each new instance will use the updated definitions without requiring "clear functions".

Rik <rik5>
Group administrator
Tue 14 Jan 2020 03:45:08 PM UTC, comment #5: 

I note that this issue is closed.
However, I find

clear classes

which for me clears practically everything in my Octave session, too heavy.
It would definitely be easier to develop my code when I could maintain the variables that are already in memory when testing a small change to my class.

Louis <louisgag>
Tue 12 Mar 2019 06:31:25 PM UTC, comment #4: 

The solution proposed does work.  Problem solved! Thank you!

Delbert Johnson <del_johnson>
Tue 12 Mar 2019 04:00:37 PM UTC, comment #3: 

Just checking for myself and all of the syntaxes below will work.


clear classes
clear functions
clear all


"clear classes" is probably the most specific and the best usage for this case.


Rik <rik5>
Group administrator
Tue 12 Mar 2019 12:17:58 AM UTC, comment #2: 

Thank you for your thorough bug report.

The correct behavior would be for Octave to reload the class definition if you run "clear" or "clear classes". Additionally, Octave could issue a warning message that the class definition file has been updated since the class was loaded, but that's of a lower priority.

If you use "clear all" or "clear classes" you should get the updated class definition the next time you create an instance of the class, can you try that and comment here if it doesn't work for you?

See bug #45893 about the remaining issue of "clear" with no args not reloading the class definition.

Mike Miller <mtmiller>
Group Member
Tue 12 Mar 2019 12:11:47 AM UTC, comment #1: 

The bug title should be corrected to say:

Edit changes to classdef object ARE NOT SEEN(executed) after saving the file and re-initializing the object.

Delbert Johnson <del_johnson>
Tue 12 Mar 2019 12:01:48 AM UTC, original submission:  

sample code:
 

classdef testprop

        properties
                test = 0;
        end

        properties (Access = protected)
                protectedtestprop = 0;
        end

        properties (Hidden = true)
                hiddentestprop = 0;
        end

end


After creating the classdef and saving it the following code works:

>> t = testprop

t =

<object testprop>

>> t.test

ans = 0

>> t.test


if I re-edit testprop and change the value of property test followed by saving the file, the result returned is still ans = 0.  The same is true if I create addition code or properties.  The return unknown errors when accessed.

If I quit octave and then re-start it the changes that were made prevously do execute successfully.  But if I make additional edit changes they are not seen when initializing the class and displaying the property that was changed in the edit process.

This problem is limited to classdef.m files.  I create a simple function in a separate file. Executed it.  Then made changes and saved it followed by calling the function again, which did execute the changes successfully.


Anonymous

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #46501:  testprop.m added by None (186B - text/plain)

 

Digest:
   bug dependencies.

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 louisgag (Posted a comment)
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by del_johnson (Posted a comment)
  • -email is unavailable- added by None (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 6 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2019-03-12 mtmiller StatusNeed Info Works For Me
        Open/ClosedOpen Closed
    2019-03-12 rik5 Operating SystemMicrosoft Windows Any
    2019-03-12 mtmiller Dependencies- Depends on bugs #45893
    2019-03-12 mtmiller StatusNone Need Info
    2019-03-12 None Attached File- Added testprop.m, #46501

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code