bugGNU Octave - Bugs: bug #32964, Inheritance and anonymous...

 
 

bug #32964: Inheritance and anonymous functions do not work together

Submitted by:  Patrick Häcker <magicmuscleman>
Submitted on:  Thu 31 Mar 2011 11:12:54 AM UTC  
 
Category: InterpreterSeverity: 3 - Normal
Priority: 5 - NormalItem Group: Incorrect Result
Status: Works For MeAssigned to: None
Originator Name: Debian 6.0Open/Closed: Closed
Release: 3.4.0Operating System: GNU/Linux

Add a New Comment(Rich Markup)
   

You are not logged in

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

 

Tue 01 Nov 2016 09:20:07 AM UTC, comment #3:

Works for me, too, nowadays (tested in Octave 4.0.3). Thanks for having a look.

Patrick Häcker <magicmuscleman>
Mon 31 Oct 2016 11:32:19 PM UTC, comment #2:

The example in this old bug report works for me with recent (and even with older) versions of Octave, closing as working. If the reporter is still around, or this problem occurs again, please file a new bug report showing the error on a supported version of Octave.

Mike Miller <mtmiller>
Project Administrator
Thu 31 Mar 2011 11:20:00 AM UTC, comment #1:

I cannot see the full text of my previous entry in the browser, so I repost it without using verbatim:

There is a problem in Octave with the combination of inherited objects and the
usage of anonymous functions/methods, which works with Matlab. It's probably
best to give an example:

Assume there is a class "Parent":
Constructor:
function parent = Parent()
parent = class(struct(), 'Parent');
end

Method:
function parentMethod(parent)
disp(['This is a method of class Parent called with an object of class ' class(parent)]);
end

Assume there is another class "Child" which inherits from "Parent":
Constructor:
function child = Child()
child = class(struct(), 'Child', Parent());
end

Now we want to test our two classes:

function testInheritance()
% This works in Matlab and in Octave
child = Child();
parentMethod(child);

% This works, too
parent = Parent();
fun = @() parentMethod(parent);
fun();

% This works in Matlab but not in Octave
fun = @() parentMethod(child);
fun();
end

The result of this test is:

This is a method of class Parent called with an object of class Child
This is a method of class Parent called with an object of class Parent
error: parentMethod: no method for class Child

So as you can see, the call of the parent method fails for inherited objects when using an anonymous function. Thus it's not possible to use higher order functions with inheritance in Octave. I attached the code as an tar file.

Patrick Häcker <magicmuscleman>
Thu 31 Mar 2011 11:12:54 AM UTC, original submission:

There is a problem in Octave with the combination of inherited objects and the usage of anonymous functions/methods, which works with Matlab. It's probably best to give an example:

Assume there is a class "Parent":
Constructor:

Patrick Häcker <magicmuscleman>

 

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

Attach File(s):
   
   
Comment:
   

Attached Files
file #23063:  testInheritance.tar added by magicmuscleman (6KiB - application/x-tar)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by mtmiller (Posted a comment)
  • -unavailable- added by rik5 (Updated the item)
  • -unavailable- added by magicmuscleman (Submitted the item)
  •  

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

    Only project members can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 4 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Mon 31 Oct 2016 11:32:19 PM UTCmtmillerStatusNone=>Works For Me
      Open/ClosedOpen=>Closed
    Thu 10 Oct 2013 07:15:08 PM UTCrik5Item GroupSegfault, Bus Error, etc.=>Incorrect Result
    Thu 31 Mar 2011 11:12:54 AM UTCmagicmusclemanAttached File-=>Added testInheritance.tar, #23063

    Back to the top


    Powered by Savane 3.1-cleanup1