bugGNU Octave - Bugs: bug #42735, subclass inheritence: symbol ops...


bug #42735: subclass inheritence: symbol ops (e.g., plus, mtimes) do not respect superiorto

Submitted by:  Colin Macdonald <cbm>
Submitted on:  Fri Jul 11 23:08:52 2014  
Category: InterpreterSeverity: 3 - Normal
Priority: 5 - NormalItem Group: Incorrect Result
Status: ConfirmedAssigned to: None
Originator Name: Open/Closed: Open
Release: devOperating System: Any

Add a New Comment (Rich MarkupRich Markup):

You are not logged in

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


Tue Nov 1 05:42:47 2016, comment #4:

This page (https://www.mathworks.com/help/matlab/matlab_oop/object-precedence-in-expressions-using-operators.html) suggests that if two user-defined classes are completely unrelated, the left-hand object's method is used (which is what Octave implements today).

So the logic that is lacking here is relationships between class inheritance (both old and new style OO), old-style superiorto/inferiorto relationships, and new-style InferiorClasses relationships.

Mike Miller <mtmiller>
Project Administrator
Tue Nov 1 05:29:17 2016, comment #3:

The cause of this behavior is right here


When a binary operator is called with one or two class arguments, the class type of the left hand argument takes precedence. There should be additional checking if they are both class types.

Can you test what Matlab does in this case if the two classes are completely unrelated (no inheritance, no superiorto declaration, just two classes that both provide plus methods)?

Mike Miller <mtmiller>
Project Administrator
Fri Jul 11 23:30:50 2014, comment #2:

Unsurprisingly, "<double> + C" seems to work. Its just P + C that does the wrong thing.

Colin Macdonald <cbm>
Fri Jul 11 23:09:38 2014, comment #1:

also present in 3.6.4.

Colin Macdonald <cbm>
Fri Jul 11 23:08:52 2014, original submission:

I have a class called parent and a class called child.

Say P is instance of parent and C is instance of child.

parent and child have "myplus" and "plus" methods.

1) P+C and C+P call different plus methods, independent of whether superiotor('parent') is set. This behaviour DOES NOT match matlab.

2) plus(P,C) and plus(C,P) call the child plus method if superiorto is set, otherwise different methods. This behaviour matches matlab 2008a.

3) myplus(P,C) and myplus(C,P) call the child myplus method if superiorto is set, otherwise different methods. This behaviour matches matlab 2008a.

Tested with plus, minus, mtimes. Tested on 3.8.1 and "hg - 1 month".

(personally, I don't see why I'd ever want the behaviour w/o superiorto, but that is not the bug here)

I'll attach my minimal example: untar and run mytest.m

Colin Macdonald <cbm>


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

Attach File(s):

Attached Files
file #31704:  inheritance.tar added by cbm (20kB - 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 cbm (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 3 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Tue Nov 1 05:29:17 2016mtmillerStatusNone=>Confirmed
      Operating SystemGNU/Linux=>Any
    Fri Jul 11 23:08:52 2014cbmAttached File-=>Added inheritance.tar, #31704

    Back to the top

    Powered by Savane 3.1-cleanup