bugGNU Octave - Bugs: bug #56953, Can not access private class...

 
 

bug #56953: Can not access private class properties from lambdas

Submitter:  Markus Ebner <seijikun>
Submitted:  Wed 25 Sep 2019 10:55:38 PM UTC
   
 
Category:  Classdef Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Fixed Assigned to:  None
Originator Name:  Open/Closed:  * Closed
Release:  * 5.1.0 Operating System:  * Any
Fixed Release:  9.1.0 Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Tue 30 Jan 2024 10:41:18 PM UTC, comment #1: 

This has been fixed somewhere in the last 4 years.  It works on the code that is about to be released as version 9.1.  Marking as Fixed and closing report.

Rik <rik5>
Group administrator
Wed 25 Sep 2019 10:55:38 PM UTC, original submission:  

In Octave, it is not possible to access private class properties (via self.<propertyname>) from within lambdas defined somewhere in the class.

Here is a small example that works in Matlab:

classdef TestClass
        properties(Access = private)
                privateProperty = 0;
        end

        methods
                function self = TestClass()
                        self.privateProperty = 5;
                        fnPtr = @() disp(self.privateProperty);
                        fnPtr();
                end
        end
end


In Octave, this outputs the error:

error: subsref: property `privateProperty' has private access and cannot be obtained in this context
error: called from
    TestClass>@<anonymous> at line 9 column 16
    TestClass at line 10 column 4


Workaround is one of:
- Remove the Access-clause on the properties
- Set Access to public (protected does not work either)
- Copy variable into "stack" before using it in the lambda, like:

tmpCopy = self.privateProperty;
fnPtr = @() disp(tmpCopy);
fnPtr();


Markus Ebner <seijikun>

 

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

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Digest:
   bug dependencies.

 

Carbon-Copy List
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by seijikun (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
    2024-01-30 rik5 StatusNone Fixed
        Open/ClosedOpen Closed
        Fixed ReleaseNone 9.1.0
    2022-03-04 mmuetzel Carbon-CopyRemoved 102357 -
    2022-03-04 mmuetzel CategoryInterpreter Classdef
    2022-02-18 siko1056 Dependencies- bugs #62077 is dependent

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code