changeset 28858:eb46f92a9ef4

maint: merge stable to default.
author John W. Eaton <jwe@octave.org>
date Mon, 05 Oct 2020 15:35:22 -0400
parents 43ad651cf5a0 (current diff) dece83bfab89 (diff)
children 20f31c0b0132
files
diffstat 2 files changed, 69 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/test/bug-58593/bug-58593.tst	Mon Oct 05 15:19:15 2020 -0400
+++ b/test/bug-58593/bug-58593.tst	Mon Oct 05 15:35:22 2020 -0400
@@ -25,16 +25,32 @@
 
 %!test <*58593>
 %! obj = myclass1 ();
-%! assert (obj.data (plus (minus (end,1), 1)), 1005)
+%! assert (obj.data (plus (minus (end,1), 1)), 1005);
+
+%!test <*58593>
+%! obj = myclass2 ();
+%! assert (obj.alldata, 1001:1005);
+
+%!test <*58593>
+%! obj = myclass2 ();
+%! assert (obj(end), 1004);
 
 %!test <*58593>
 %! obj = myclass2 ();
-%! assert (obj.alldata, 1001:1005)
+%! assert (obj.data(end), 1005);
+
+%!test <*58593>
+%! obj = myclass2 ();
+%! obj.alldata = 1:5;
+%! assert (obj.data, 1:5);
 
 %!test <*58593>
 %! obj = myclass2 ();
-%! assert (obj(end), 1004)
+%! obj(end) = -1;
+%! assert (obj.data, [1001:1003, -1, 1005]);
 
 %!test <*58593>
 %! obj = myclass2 ();
-%! assert (obj.data(end), 1005)
+%! obj.data(end) = -1;
+%! assert (obj.data, [1001:1004, -1]);
+
--- a/test/bug-58593/myclass2.m	Mon Oct 05 15:19:15 2020 -0400
+++ b/test/bug-58593/myclass2.m	Mon Oct 05 15:35:22 2020 -0400
@@ -4,37 +4,74 @@
   end
 
   methods
-    function obj = myclass2(data)
+    function obj = myclass2 ()
       obj.data_ = 1001:1005;
     end
 
-    function r = subsref(obj,S)
-      switch S(1).type
+    function r = subsref (obj, S)
+      switch (S(1).type)
       case '.'
-        switch S(1).subs
+        switch (S(1).subs)
         case 'data'
           % Transform: obj.data --> obj.data_
-          r = subsref (obj.data_, S(2:end));
+          r = obj.data_;
+          if (length (S) > 1)
+            r = subsref (r, S(2:end));
+          end
         case 'alldata'
           % Transform: obj.data --> obj.data_(1:end)
-          % This expression should trigger *builtin* subsref *twice* (one
+          % This statement should trigger *builtin* subsref *twice* (one
           % for the evaluation of 'end', and the other for the whole rvalue).
           % 'end' here is also builtin 'end'
           r = obj.data_(1:end);
+
+          if (length (S) > 1)
+            r = subsref (r, S(2:end));
+          end
         otherwise
-          error('Incorrect usage')
+          error ('Incorrect usage');
         end
       case '()'
-        % Transform: obj(index) --> obj.data_(1:end)
-        r = subsref(obj.data_,S);
+        % Transform: obj(index) --> obj.data_(index)
+        r = subsref (obj.data_, S);
       otherwise
-        error('Incorrect usage')
+        error ('Incorrect usage');
       end
     end
 
-    function r = end(obj,k,n)
+    function obj = subsasgn (obj, S, B)
+      switch (S(1).type)
+      case '.'
+        switch (S(1).subs)
+        case 'data'
+          % Transform: obj.data --> obj.data_
+          if length(S)>1
+            B = subsasgn (obj.data_, S(2:end), B);
+          end
+          obj.data_ = B;
+        case 'alldata'
+          % Transform: obj.data --> obj.data_(1:end)
+          if length(S)>1
+            B = subsasgn (obj.data_(1:end), S(2:end), B);
+          end
+          % This statement should trigger *builtin* subsref to evaluate 'end',
+          % then *builtin* subsasgn for the whole assignment expression
+          % 'end' here is also builtin 'end'
+          obj.data_(1:end) = B;
+        otherwise
+          error('Incorrect usage');
+        end
+      case '()'
+        % Transform: obj(index) --> obj.data_(index)
+        obj.data_ = subsasgn (obj.data_, S, B);
+      otherwise
+        error ('Incorrect usage');
+      end
+    end
+
+    function r = end (obj, k, n)
       % We subtract 1 from the "real" end of obj.data_
-      r = builtin('end',obj.data_,k,n)-1;
+      r = builtin ('end', obj.data_, k, n) - 1;
     end
   end
 end