changeset 26761:81b7bef8192c

maint: Merge stable to default.
author John W. Eaton <jwe@octave.org>
date Thu, 21 Feb 2019 07:18:26 +0000
parents 4cc0df2c5168 (current diff) 17d806c3f7cd (diff)
children c97a65af7c4b
files libinterp/octave-value/ov-classdef.cc test/module.mk
diffstat 5 files changed, 73 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/octave-value/ov-classdef.cc	Thu Feb 21 05:12:54 2019 +0000
+++ b/libinterp/octave-value/ov-classdef.cc	Thu Feb 21 07:18:26 2019 +0000
@@ -906,8 +906,28 @@
 
   // This variant of subsref is used to create temporary values when doing
   // assignment with multi-level indexing.  AFAIK this is only used for internal
-  // purpose (not sure we should even implement this) and any overload subsref
-  // should not be called.
+  // purpose (not sure we should even implement this).
+
+  cdef_class cls = object.get_class ();
+
+  if (! in_class_method (cls))
+    {
+      cdef_method meth = cls.find_method ("subsref");
+
+      if (meth.ok ())
+        {
+          octave_value_list args;
+
+          args(1) = make_idx_args (type, idx, "subsref");
+
+          count++;
+          args(0) = octave_value (this);
+
+          retval = meth.execute (args, 1, true, "subsref");
+
+          return retval.length () > 0 ? retval(0) : octave_value ();
+        }
+    }
 
   retval = object.subsref (type, idx, 1, skip, cdef_class (), auto_add);
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/bug-55223/bug-55223.tst	Thu Feb 21 07:18:26 2019 +0000
@@ -0,0 +1,22 @@
+## Copyright (C) 2018 Sébastien Villemot <sebastien@debian.org>
+##
+## This file is part of Octave.
+##
+## Octave is free software: you can redistribute it and/or modify it
+## under the terms of the GNU General Public License as published by
+## the Free Software Foundation, either version 3 of the License, or
+## (at your option) any later version.
+##
+## Octave is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with Octave; see the file COPYING.  If not, see
+## <https://www.gnu.org/licenses/>.
+
+%!test <*55223>
+%! x = class_bug55223 ();
+%! x{2}(2) = 3;
+%! assert (x{2}(2), 3);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/bug-55223/class_bug55223.m	Thu Feb 21 07:18:26 2019 +0000
@@ -0,0 +1,23 @@
+classdef class_bug55223<handle
+  properties
+    x
+  endproperties
+
+  methods
+    function obj = class_bug55223 ()
+      obj.x = eye (4);
+    endfunction
+
+    function val = subsref (obj, S)
+      if (length (S) == 2 && S(1).type == "{}" && S(2).type == "()")
+        val = obj.x(S(1).subs{1}, S(2).subs{1});
+      endif
+    endfunction
+
+    function obj = subsasgn (obj, S, val)
+      if (length (S) == 2 && S(1).type == "{}" && S(2).type == "()")
+        obj.x(S(1).subs{1}, S(2).subs{1}) = val;
+      endif
+    endfunction
+  endmethods
+endclassdef
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/bug-55223/module.mk	Thu Feb 21 07:18:26 2019 +0000
@@ -0,0 +1,5 @@
+bug_55223_TEST_FILES = \
+  %reldir%/bug-55223.tst \
+  %reldir%/class_bug55223.m
+
+TEST_FILES += $(bug_55223_TEST_FILES)
--- a/test/module.mk	Thu Feb 21 05:12:54 2019 +0000
+++ b/test/module.mk	Thu Feb 21 07:18:26 2019 +0000
@@ -77,6 +77,7 @@
 include %reldir%/bug-53027/module.mk
 include %reldir%/bug-53468/module.mk
 include %reldir%/bug-54995/module.mk
+include %reldir%/bug-55223/module.mk
 include %reldir%/class-concat/module.mk
 include %reldir%/classdef/module.mk
 include %reldir%/classdef-multiple-inheritance/module.mk