bugGNU Octave - Bugs: bug #48802, function overload resolution on...

 
 

bug #48802: function overload resolution on function handles fails on classdef methods defined in class body

Submitted by:  Mike Miller <mtmiller>
Submitted on:  Tue 16 Aug 2016 07:49:35 PM UTC  
 
Category:  Interpreter Severity:  1 - Wish
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Confirmed Assigned to:  None
Originator Name:  Open/Closed:  Open
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.

 

Wed 20 Feb 2019 10:36:30 AM UTC, comment #5:

Regarding comment #3: In the original example I get:

Changing all methods to be static in c2 the output of run_test.m:

Test follows in the next post.

Kai Torben Ohlhus <siko1056>
Project Member
Fri 15 Feb 2019 06:11:40 PM UTC, comment #4:

I can't test that for you, but Matlab fundamental classes are documented at https://www.mathworks.com/help/matlab/matlab_prog/fundamental-matlab-classes.html, all builtin numeric types, logical, char, struct, cell, and table.

I don't know what they are trying to say with "a function in a class that is not a fundamental Matlab class", since they don't give a counterexample. When would the binding ever occur at the time of declaration? I have no idea. That seems like another inconsistency, I would expect function handles to always be symbolic and only bind to the function when they are invoked with their arguments.

Mike Miller <mtmiller>
Project Administrator
Thu 07 Feb 2019 07:52:06 PM UTC, comment #3:

I'm a bit confused by the statement in the Matlab docs that is quoted in the original submission. What is meant by "if the function you specify overloads a function in a class that is not a fundamental Matlab class"? What is a "fundamental Matlab class"? Is that a type like in32 or double or struct, or any class that is distributed as a part of Matlab, or what?

I think I may need some more examples to understand how things are expected to work.

What is supposed to happen for the following

I guess my question is, precisely when is binding deferred?

John W. Eaton <jwe>
Project Administrator
Fri 04 Jan 2019 08:11:05 PM UTC, comment #2:

The problem seems to be that the function make_fcn_handle in ov-fcn-handle.cc does the wrong thing. It is called when evaluating the "@double" expression in an attempt to bind the function handle early. It works for overloaded methods if they are defined in a separate file because it does search the loadpath for overloaded function names. But to do that for methods in classdef classes would require parsing all possible classdef files just to find out whether there are some overloads. So the right thing seems to be to avoid binding function handles until they are called since there is no reasonable way to determine what function to call until a call is actually attempted with arguments. But the fix is not as simple as just having a function handle store the name of the function. It needs more context than that to properly resolve subfunctions, nested functions, local functions, etc. So I see no simple fix. This bug should probably also reference the one about handles to nested functions, bug #39257. These issues are related and I think fixing them properly will require a bit of work.

John W. Eaton <jwe>
Project Administrator
Sat 20 Aug 2016 08:42:46 PM UTC, comment #1:

This bug only applies to classdef function overloads that are defined in the "methods" block of a class definition.

For old-style classes, all methods are defined in separate .m function files. If this is also done for a classdef class, then this bug does not apply.

Mike Miller <mtmiller>
Project Administrator
Tue 16 Aug 2016 07:49:35 PM UTC, original submission:

According to the Matlab documentation, a function handle should behave with respect to overloading the same way as any other function call would.

> Overloading — If the function you specify overloads a function in a class that is not a fundamental MATLAB class, the function is not associated with the function handle at the time it is constructed. Instead, MATLAB considers the input arguments and determines which implementation to call at the time of evaluation.


(From https://www.mathworks.com/help/matlab/matlab_prog/creating-a-function-handle.html.)

In other words, if I have a user-defined class that implements a double() conversion method,

this snippet should work correctly. Currently, Octave throws a "invalid conversion from object to double" error.

Mike Miller <mtmiller>
Project Administrator

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #46312:  bug48802_comment03.zip added by siko1056 (857B - application/zip)

 

Depends on the following items: None found

Digest:
   bug dependencies.

 

Carbon-Copy List
  • -email is unavailable- added by siko1056 (Posted a comment)
  • -email is unavailable- added by jwe (Posted a comment)
  •  

    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 6 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2019-02-20 siko1056 Attached File- => Added bug48802_comment03.zip, #46312
    2019-02-15 mtmiller Carbon-CopyRemoved 80942 => -
    2019-01-04 mtmiller Dependencies- => bugs #55383 is dependent
    2016-08-20 mtmiller StatusNone => Confirmed
        Summaryfunction overload resolution should be performed on function handles => function overload resolution on function handles fails on classdef methods defined in class body
    2016-08-20 mtmiller Dependencies- => bugs #48837 is dependent

    Back to the top


    Powered by Savane 3.4