bugGNU Octave - Bugs: bug #51599, Anonymous functions that reference...


bug #51599: Anonymous functions that reference local functions within classdef files don't work

Submitted by:  Piotr Held <jsoh425>
Submitted on:  Fri 28 Jul 2017 12:45:12 AM UTC  
Category:  Interpreter Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Fixed Assigned to:  Kai Torben Ohlhus <siko1056>
Originator Name:  Piotr Held Open/Closed:  Closed
Release:  dev Operating System:  Any

Add a New Comment (Rich Markup)

You are not logged in

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


( Jump to the original submission)

Mon 31 Jul 2017 11:56:48 AM UTC, comment #7: 
Kai Torben Ohlhus <siko1056>
Project MemberIn charge of this item.
Mon 31 Jul 2017 09:44:04 AM UTC, comment #6: 

I checked with MATLAB R2017a and can confirm the original issue.  Calling a class local function directly was fixed recently in bug #41723 and it should be possible to create anonymous functions to those methods, as well.

The patch in file #41370 works like a charm and I push it soon after a few code style checks.

Kai Torben Ohlhus <siko1056>
Project MemberIn charge of this item.
Sat 29 Jul 2017 03:48:02 PM UTC, comment #5: 

I didn't mean to blame Philip, though I do agree that my response was poorly phrased. I do apologize for that.

To be clear there are two things that I'm trying to do:
1. Create a handle to a method.
2. Create an anonymous function that references local functions within classdef.

In your opinion should those be separate bug reports or just one?  (though I agree that 3 is too much)

I thought of them as separate, since the tests and the solution are both different.

Piotr Held <jsoh425>
Sat 29 Jul 2017 02:58:03 PM UTC, comment #4: 

We are all volunteers here, so there is no need to "blame" Philip for his attempt to point you to a feature of Savannah.  As Philip does in his screenshot, I see that for commenting there is a preview button.  But you are right, too.  When submitting a new item, I don't see any preview button.

I would like to encourage you not to submit too many bug reports about one problem you are struggling with, especially if it would even not work in Matlab.  Bugs bug #51599, bug #51586, and bug #51567 seem to deal all with your attempt to do one thing with a classdef class.  That feature is not reliable at the moment, so you cannot expect all functions to properly work with classdef at the moment.  It costs me more time to grasp all your ideas spread into several bug reports, than to ask in the help mailing list for a proper solution.

Kai Torben Ohlhus <siko1056>
Project MemberIn charge of this item.
Sat 29 Jul 2017 12:02:05 AM UTC, comment #3: 

When submitting new bugs, NOT when commenting, you gave the wrong screenshot.

Anyway, I think I have a patch for the problem. If anyone wants to look at it. I am attaching it. I also included tests for the problem in the changeset.

(file #41370)

Piotr Held <jsoh425>
Fri 28 Jul 2017 07:07:50 PM UTC, comment #2: 

At least in my browser (Seamonkey 2.46) I DO see a preview button.
And it works perfectly, see attached 2nd. pic

Philip Nienhuis <philipnienhuis>
Project Member
Fri 28 Jul 2017 12:47:45 AM UTC, comment #1: 

I am sorry, again... (there should be a preview when submitting new bugs)

The interpreter returns with error:

'my_helper' undefined near line 7 column 30

However, when calling 'my_helper' directly, the code executes correctly.

I am attaching a test case for this problem.

Piotr Held <jsoh425>
Fri 28 Jul 2017 12:45:12 AM UTC, original submission:  

If you create an anonymous function within a class method that references a local function the anonymous function will fail when executed. Even when called from within another class method.

So with the following code:

classdef local_classdef_anon_fcn < handle
    function foo (self)
      self.anon_fcn = @(x) my_helper(x+1);
    function ret = bar (self, val)
      ret = self.anon_fcn (val);

function ret = my_helper (val)
  ret = val + 1;

When you call bar, the interpreter will not return with error:

Piotr Held <jsoh425>


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

Attach Files:

Attached Files
file #41370:  patch_bug51599.diff added by jsoh425 (4KiB - text/x-patch)
file #41364:  local_classdef_anon_fcn.m added by jsoh425 (418B - text/x-objcsrc)


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -email is unavailable- added by siko1056 (Posted a comment)
  • -email is unavailable- added by jsoh425 (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.




    Follow 8 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2017-07-31 siko1056 StatusIn Progress => Fixed
        Open/ClosedOpen => Closed
    2017-07-31 siko1056 StatusPatch Submitted => In Progress
        Assigned toNone => siko1056
    2017-07-29 siko1056 StatusNone => Patch Submitted
    2017-07-29 jsoh425 Attached File- => Added patch_bug51599.diff, #41370
    2017-07-28 philipnienhuis Attached File- => Added Savannah_preview_button.PNG, #41368
    2017-07-28 jsoh425 Attached File- => Added local_classdef_anon_fcn.m, #41364

    Back to the top

    Powered by Savane 3.5