bugGNU Octave - Bugs: bug #67197, Class with abstract properties can...

 
 

bug #67197: Class with abstract properties can be instantiated, but should not be able to be

Submitter:  Thomas <kolmanthomas>
Submitted:  Sat 07 Jun 2025 11:14:02 PM UTC
   
 
Category:  Classdef Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Missed Error or Warning
Status:  None Assigned to:  None
Originator Name:  Thomas K. Open/Closed:  * Open
Release:  * dev Release: 
Operating System:  * Mac OS Fixed Release:  None
Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Mon 09 Jun 2025 05:08:56 PM UTC, comment #1: 

There's a similar problem for abstract methods (could be a second bug report if need be), where the class can be instantiated in Octave (but not in MATLAB).


classdef AbstractMethodsClass
    methods (Abstract)
        function result = f(obj)
        end
    end
end


Luckily you can't call the abstract method (Octave responds with an error).

After a second look at the problem, I'm not even sure we should emulate MATLAB's behaviour for abstract methods. From the documentation,

> A class is abstract when it declares:
>
>     The Abstract class attribute
>
>     An abstract method
>
>     An abstract property


which seems redundant to me, since the class attribute Abstract becomes rather useless (maybe under certain uses, you could declare abstract classes with no properties or methods to group subclasses, to introduce some typing, but that's the only reason I can think of).

Thomas <kolmanthomas>
Sat 07 Jun 2025 11:14:02 PM UTC, original submission:  

Here's an example classdef:

classdef AbstractPropertiesClass
    properties (Abstract)
        a
    end
end

Instantiation of the class

absPropClass = AbstractPropertiesClass

works without error on Octave.

It's also possible to set and change the abstract property in Octave.

MATLAB's behaviour is to provide an error on the attempt at instantiation:

Abstract classes cannot be instantiated. Class 'AbstractPropertiesClass' defines abstract methods and/or properties.


Thomas <kolmanthomas>

 

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

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by kolmanthomas (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 group members can vote.

     

    No changes have been made to this item

    Back to the top

    Powered by Savane 3.15-26b0.
    Corresponding source code