bugGNU Octave - Bugs: bug #55383, Function handle does not evaluate...

 
 

bug #55383: Function handle does not evaluate the correct function for the given object type

Submitted by:  None
Submitted on:  Fri 04 Jan 2019 11:59:54 AM UTC  
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Unexpected Error
Status:  Fixed Assigned to:  None
Originator Name:  Jonas Originator Email:  -email is unavailable-
Open/Closed:  Closed Release:  4.2.2
Operating System:  GNU/Linux

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)

Fri 04 Jan 2019 07:26:21 PM UTC, comment #7: 

Ok, sorry for not looking deeper, you are right. It looks like the syntax

logFH = @(obj)log(obj);
logFH (x)

does work in Octave 4.4, but bug #48802 is still present, so using the syntax

logFH = @log;
logFH (x)

fails with the error reported here. So closing this as fixed for Octave 4.4, with bug #48802 still open.

Mike Miller <mtmiller>
Project Administrator
Fri 04 Jan 2019 07:18:07 PM UTC, comment #6: 

I can duplicate this problem with Octave 4.2.2, but it seems to work correctly for me with 4.4.1 and the current sources.

John W. Eaton <jwe>
Project Administrator
Fri 04 Jan 2019 07:16:51 PM UTC, comment #5: 

Thanks, closing this report as a duplicate, feel free to comment or add yourself on the cc list for bug #48802.

Mike Miller <mtmiller>
Project Administrator
Fri 04 Jan 2019 07:14:11 PM UTC, comment #4: 

I agree it is a duplicate, and it works as you expected if the method definition is in a separate file.

Anonymous
Fri 04 Jan 2019 06:16:43 PM UTC, comment #3: 

I think this looks like a duplicate of bug #48802, do you agree? Does your example also work for you if you move the definition of 'log' into a separate @Matrix/log.m function file?

Mike Miller <mtmiller>
Project Administrator
Fri 04 Jan 2019 12:21:12 PM UTC, comment #2: 

there is a typo in the class. "self" should be "obj" but its irrelevant to the problem.

Anonymous
Fri 04 Jan 2019 12:16:28 PM UTC, comment #1: 

It seems to be specific to functions with one argument.
With "times" no error occurs:

classdef Matrix < handle
  properties
    value
  end
  methods (Static)
  end
  methods
    function obj = Matrix(value)
      self.value = value;
    end
    function r = log(obj)
      r = log(obj.value);
    end
    function r = times(obj,b)
      r = times(obj.value,b);
    end
  end
end

timesFH = @(obj,b)times(obj,b);
a = Matrix(3);
timesFH(a,12);

Anonymous
Fri 04 Jan 2019 11:59:54 AM UTC, original submission:  

A minimum failing example and fix is in the attachment.

Assuming you have a class that implements a method with the name of a builtin function, e.g. log, sum, times...

Then you create a function handle to the method/function and evaluate the function handle on an object of the class:

logFH = @(obj)log(obj);
a = Matrix(4)
logFH(a);

Will fail with:
error: log: not defined for object

I seems that Octave tries to evaluate the builtin log instead of the log method of the object.

The fix is the following:

logFH = @(obj,varargin)log(obj);
a = Matrix(4)
logFH(a);

Anonymous

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #45865:  Matrix.m added by None (229B - text/x-objcsrc)
file #45866:  testMatrix.m added by None (130B - text/x-objcsrc)

 

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 None (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 9 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2019-01-04 mtmiller StatusNone => Fixed
        Open/ClosedOpen => Closed
    2019-01-04 jwe StatusDuplicate => None
        Open/ClosedClosed => Open
    2019-01-04 mtmiller StatusNone => Duplicate
        Open/ClosedOpen => Closed
        Dependencies- => Depends on bugs #48802
    2019-01-04 None Attached File- => Added Matrix.m, #45865
        Attached File- => Added testMatrix.m, #45866

    Back to the top


    Powered by Savane 3.5