bugGNU Octave - Bugs: bug #51659, Calling 'methods' on self causes...


bug #51659: Calling 'methods' on self causes syntax error

Submitter:  Piotr Held <jsoh425>
Submitted:  Fri 04 Aug 2017 05:57:30 PM UTC
Category:  Octave Function Severity:  3 - Normal
Priority:  3 - Low Item Group:  Matlab Compatibility
Status:  Confirmed Assigned to:  None
Originator Name:  Piotr Held Open/Closed:  * Open
Release:  * dev Operating System:  * Any
* Mandatory Fields

Add a New Comment (Rich Markup)

Comment Type & Canned Response:


( Jump to the original submission )

Sun 03 Mar 2019 06:00:29 AM UTC, comment #6: 

Even though this this is 18 months old, I can confirm the discrepancy with Matlab.

Rik <rik5>
Project Administrator
Mon 07 Aug 2017 05:41:01 PM UTC, comment #5: 

And also 'methods', 'properties' or 'events' are illegal names for properties or events.

However they are not illegal names for methods (which I guess is so that you could overload what methods() or properties() or events() does?). So you can have:

  function methods (self) % events or proprties
    a = methods (self);

and you will not get a syntax error. It will only spit out an error when calling the method itself. If the method does actually make sense, calling methods(obj_classname) actually executes the method 'methods' instead of listing all the methods of obj_classname.

Piotr Held <jsoh425>
Mon 07 Aug 2017 05:26:14 PM UTC, comment #4: 

I did some investigation into this matter and here are my results:

Using properties(), methods (), events() inside 'properties' tag is illegal:

  prop1 = properties ('classname'); %or methods or events

Using properties(), methods(), events() from 'methods' tag is legal:

  function foo (self)
    a = methods (self); % or methods ('classname'), or properties, or events

Would you like me test more things out?

Piotr Held <jsoh425>
Sat 05 Aug 2017 09:09:27 PM UTC, comment #3: 

I just wanted to understand whether these classdef section tags (methods, events, properties, etc.) are all only keywords inside classdef blocks, and only outside of one of the sections.  If that's the way things work, then I think the problem would be relatively easy to fix.

John W. Eaton <jwe>
Project Administrator
Sat 05 Aug 2017 01:23:23 AM UTC, comment #2: 

If you want to close the bug, that's fine. I do see your point. If you want the answer to what methods(self) returns, it's what you'd expect: 'foo' and 'm1'.

The way someone was using it was to try to randomly call class methods for test cases. So they had a method (within the test class):

function testShuffle (self)
  methodNames = methods (self);
  for i=1:length(methodNames)
    eval(['self.' methodNames{i}]);

Obviously the code does a little more (it actually shuffles) but that's the just of it.

Do you have some suggestions of how to get around that?

Piotr Held <jsoh425>
Fri 04 Aug 2017 10:50:40 PM UTC, comment #1: 

OK, so "methods" should not be considered a keyword inside a methods block.  That makes sense.  Also, I'm assuming that if there were a functions called properties, events, or enumerations, that they should also not be considered keywords inside functions defined in the classdef methods block?  What should happen for something like this:

classdef foo
    function m1 (self)
      methods (self)

for example?  Or what about something like this:

classdef foo
    properties, events, methods

?  Does that make an enumeration with those names, or is it supposed to be an error?

John W. Eaton <jwe>
Project Administrator
Fri 04 Aug 2017 05:57:30 PM UTC, original submission:  

When calling methods on self the interpreter calls a syntax error. Which kind of makes sense since it hasn't yet interpreted the whole class yet, however Matlab lets you do this. Let me give an example.

Consider the following code:

classdef test_methods <handle
    function tst1 (self)
      methodNames = methods (self);

%! a = test_methods;
%! a.tst1();

When calling 'test test_methods' the interpreter responds with:

parse error near line 6 of file [...]/test_methods.m

  syntax error

>>>       m = methods (self);

I will upload this as a file as well.

Piotr Held <jsoh425>


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

Attach Files:

Attached Files
file #41413:  test_methods.m added by jsoh425 (162B - 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 rik5 (Posted a comment)
  • -email is unavailable- added by jwe (Posted a comment)
  • -email is unavailable- added by jsoh425 (Submitted the item)

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only project members can vote.





    Follow 3 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2019-03-03 rik5 Priority5 - Normal 3 - Low
        StatusNone Confirmed
    2017-08-04 jsoh425 Attached File- Added test_methods.m, #41413

    Back to the top

    Powered by Savane 3.9