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


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

Submitted by:  Markus Ebner <seijikun>
Submitted on:  Wed 25 Sep 2019 10:55:38 PM UTC  
Category:  Interpreter Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  None Assigned to:  None
Originator Name:  Open/Closed:  Open
Release:  5.1.0 Operating System:  Any

Add a New Comment (Rich Markup)

You are not logged in

Please log in, so followups can be emailed to you.


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;

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

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);

Markus Ebner <seijikun>


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

Attach Files:

No files currently attached


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -email is unavailable- added by seijikun (Submitted the item)

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.




    No changes have been made to this item

    Back to the top

    Powered by Savane 3.5