Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R2016a: error constructing class when package & class name are equal

Tags:

oop

matlab

Suppose I have the following directory structure:

Rootdir
└── +PkgClsName
    └── @PkgClsName
        └── PkgClsName.m

PkgClsName.m contains the following:

classdef PkgClsName < handle

    methods

        % Constructor
        function obj = PkgClsName()            
        end

        % Deep-copy handle object
        function new_obj = copy(obj)             
            new_obj = PkgClsName.PkgClsName();                            
        end

    end

end

Then, in R2016a, the following happens:

>> T = PkgClsName.PkgClsName;
>> T.copy()

One or more output arguments not assigned during call to "_mcos_superclass_implicit_construct".

Error in PkgClsName.PkgClsName

Error in PkgClsName.PkgClsName/copy (line 11)
            new_obj = PkgClsName.PkgClsName();

This does not happen in R2010a, R2014a and R2017a, pointing to (yet another) bug in R2016a...

The issue is because the package and class name are identical; changing the naming scheme such that they differ, fixes the issue. However, since the package name and class name have to be used explicitly in all functions/classes using the class, these names are now hard-coded in at least 600 files. That, and I have similar constructions for several other classes...I'd rather leave this all intact.

I was hoping to find a patch for this, but could not; am I overlooking it? Did anyone else encounter this? Anyone knows of an easy fix?

like image 391
Rody Oldenhuis Avatar asked Nov 29 '25 07:11

Rody Oldenhuis


1 Answers

It's already reported as bug report number 1314646, present in R2015b and R2016a, and fixed in R2016b.

I'm afraid there's no workaround, other than to not use the same name for package and class.

like image 58
Sam Roberts Avatar answered Dec 01 '25 23:12

Sam Roberts



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!