octave-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-bug-tracker] [bug #54966] Error when assigning array to an objec


From: Kai Torben Ohlhus
Subject: [Octave-bug-tracker] [bug #54966] Error when assigning array to an object implementing subsasgn() subscripted using "{}"
Date: Tue, 12 Feb 2019 07:16:13 -0500 (EST)
User-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.96 Safari/537.36

Follow-up Comment #1, bug #54966 (project octave):

This problem is still present in the current stable version 5.0.91.

While investigating the problem, I found a hack for 4.4.1 and 5.0.91, which of
course is no solution at all.  Modify your exampleclass by adding a numel
method which only returns "1":


classdef exampleclass
  
  properties
    b = {1, 2};
  end
  
  methods
    function ret = numel (obj)
      ret = 1;
    end
    
    function varargout = subsasgn (obj, idx, rhs)
      disp (idx)
      switch idx(1).type
        case '()'
          obj.b = subsasgn (obj.b, idx, rhs);
          varargout = {obj};
        case '{}'
          idx(1).type = '()';
          obj.b = subsasgn (obj.b, idx, rhs);
          varargout = {obj};
        otherwise
          varargout = {builtin('subsasgn', obj, idx, rhs)};
      end
    end
  end
  
end


Some explanation:

The error message you are facing is called 


err_invalid_structure_assignment ()


from "libinterp/corefcn/errwarn.h".  The only occurrence of this message is
libinterp/parse-tree/pt-eval.cc (line 2678) [1] when the left-hand side of the
assignment is checked for "numel != 1".

I think there must be added an exception for objects, but it seems to be
useful for structs.  At the moment I cannot come up with a proper solution to
this.

[1]
https://hg.savannah.gnu.org/hgweb/octave/file/7b9a5ab8350f/libinterp/parse-tree/pt-eval.cc#l2678

    _______________________________________________________

Reply to this item at:

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

_______________________________________________
  Message sent via Savannah
  https://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]