bugGNU Octave - Bugs: bug #67361, Classdef property and method...

 
 

bug #67361: Classdef property and method should not have the same name

Submitter:  Thomas <kolmanthomas>
Submitted:  Sun 27 Jul 2025 06:02:18 PM UTC
   
 
Category:  Classdef Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Confirmed Assigned to:  None
Originator Name:  Thomas Kolman Open/Closed:  * Open
Release:  * dev Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Post a Comment

Add a New Comment Rich Markup
   

Discussion

Mon 28 Jul 2025 03:14:19 PM UTC, comment #2: 

Marking as Confirmed.

I totally agree that it is a bad idea to have a property and a method of the same name.  Even if you establish a priority, such as property is called before method, that means having to learn a completely arbitrary rule.

I like the idea of pooling the names and checking for uniqueness among the broader list.

I think @jwe added that check in classdef so I'm adding him to the CC list for this bug report.

Rik <rik5>
Group administrator
Mon 28 Jul 2025 07:11:39 AM UTC, comment #1: 

Since 10.1 release, classdefs are not allowed to have duplicate names in properties or methods. Perhaps, this is an easy fix to extend the unique check by pooling methods and properties together. I am in favor of this change, because it also avoids confusion and possible crashes regarding documentation of properties and methods in classdefs, since there is no way to distinguish what the user is asking for when typing

help Foo.domain


Andreas Bertsatos <pr0m1th3as>
Sun 27 Jul 2025 06:02:18 PM UTC, original submission:  

Here's an example classdef demonstrating the issue.

classdef Foo
    properties
        domain = [ -1, 1 ];
    end

    methods
        function retval = domain(obj)
            retval = [ -5, 5 ];
        end
    end
end

In MATLAB R2024, you can't instantiate this classdef

>> Foo
Error using Foo
Error: File: Foo.m Line: 7 Column: 9
'domain' is already defined as a property.


In Octave, however, instantiation happens without error

octave:1> Foo
ans =

  Foo object with properties:

      domain: [-1, 1]


A similar problem is given by bug#55767, but that's for a property with the same name as a classdef. I am not explicitly advocating for this to change, I just wanted to document the discrepancy.

One caveat: if you make a class folder, with
@Foo
-- Foo.m
-- domain.m

Foo.m looks like

classdef Foo
    properties
        domain = [ -1, 1 ];
    end
end

domain.m looks like

function retval = domain(obj)
    retval = [ -5, 5 ];
end


then this is allowed in MATLAB, and Foo can be instantiated without error. It is also currently allowed in Octave as well, I just want to clarify that this should remain possible.



Thomas <kolmanthomas>

 

Attached Files

This item currently has no attached files.

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

Attach Files:
   
   
Comment:
   

 

Dependencies

This item does not depend on any other items.

No items depend on this one.

 

Mail Notification Carbon-Copy List

Carbon-Copy List
  • -email is unavailable- added by rik5
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by pr0m1th3as (Posted a comment)
  • -email is unavailable- added by kolmanthomas (Submitted the item)
  •  

    Votes

    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 group members can vote.

     

    History

    Follow 2 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2025-07-28 rik5 Carbon-Copy- Added jwe
    2025-07-28 rik5 StatusNone Confirmed

    Back to the top

    Powered by Savane 3.16.
    Corresponding source code