[bug #59775] "error: mark_as_constructed: invalid object" when constructor returns classdef array

Mark Goldberg <[email protected]>
Newsgroups gmane.comp.gnu.octave.bugs
Message-ID <[email protected]>
Please use the bug tracker to post updates to a bug report.  The mailing list is intended as a read-only notification stream.  Info posted to this mailing list address won't appear in the tracker database where it is most useful.

Follow-up Comment #8, bug #59775 (group octave):

Here is yet another classdef array issue. I have not located an existing bug
report for this, so I'm happy to open a new one unless advised otherwise.

As the following shows, operating on a classdef object array is okay outside
of the class. However, when performing the same operation in a class method an
indexing error is issued.

classdef mre4
    properties
        A
    end
    methods
        function obj = mre4(a)
            if nargin > 0
                if isscalar(a)
                    obj.A = a;
                else
                    obj(size(a)) = mre4();
                    c = num2cell(a);
                    [obj.A] = c{:};
                end
            end
        end
        function obj = norm(objin)
            a = [objin.A];
            b = a / mean(a);
            obj = mre(b);
        end
    end
end


octave:101> m = mre4([1,2,3]);
octave:102> a = [m.A]; %ok
octave:103> b = a/mean(a); % ok
octave:104> p = mre4(b); % ok
octave:105> p(1)
ans =
  1x1 mre4 object with properties:
      A: 0.5000
octave:106> p(2)
ans =
  1x1 mre4 object with properties:
      A: 1
octave:107> p(3)
ans =
  1x1 mre4 object with properties:
      A: 1.5000
octave:108> p2 = m.norm(); %not ok
error: can't perform indexing operation on array of mre4 objects
octave:109> 




    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?59775>

_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/
signature.asc (application/pgp-signature, 228 B)
-----BEGIN PGP SIGNATURE-----

iHUEABYIAB0WIQQk97aszIMMAvLLwm6qLAuaBUf3TgUCaaxzRAAKCRCqLAuaBUf3
TpTDAQC/RNL5fsgA8YxMgl+z6YBdbXX/XQBobD25AKVNv1nnpgEA7cMaAqG+p230
/Nf0NCSlbpyXy9LDu7G+rZnHdG5jZwQ=
=dc0d
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.