changeset 29137:fd8e536d166e

+containers.Map.m: Fix subsref errors (bug #59607). * +containers/Map.m (subsref): Add special case to "values" decode of '.' subsref to handle 2-input form of values(). For "()" type, change code for isKey, delete code to remove "()" indexing from s struct in a way such that further indexing, if present, will actually work. Add BIST tests for bug #59607 and for using subsequent indexing on isKey call.
author Rik <rik@octave.org>
date Wed, 02 Dec 2020 20:00:49 -0800
parents 9560c8c374dc
children eacd1a3417c3
files scripts/+containers/Map.m
diffstat 1 files changed, 26 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/+containers/Map.m	Wed Dec 02 17:18:53 2020 -0500
+++ b/scripts/+containers/Map.m	Wed Dec 02 20:00:49 2020 -0800
@@ -379,7 +379,13 @@
             case "keys"
               sref = keys (this);
             case "values"
-              sref = values (this);
+              if (numel (s) > 1
+                  && strcmp (s(2).type, "()") && ! isempty (s(2).subs))
+                sref = values (this, s(2).subs{1});
+                s(1) = [];
+              else
+                sref = values (this);
+              end
             case "size"
               sref = size (this);
             case "length"
@@ -397,7 +403,7 @@
                 error ("containers.Map: input argument 'KeySet' is missing");
               endif
               sref = feval (s(1).subs, this, s(2).subs{1});
-              s = s(3:end);
+              s(1) = [];
             otherwise
               error ("containers.Map: unknown property '%s'", s(1).subs);
           endswitch
@@ -821,6 +827,24 @@
 %! m3 = [m2, m1];
 %! assert (m3.KeyType, "single");
 
+## Test subsref calls
+%!test <*59607>
+%! months = {'Jan', 'Feb', 'Mar', 'Apr'};
+%! vals = [10, 11, 12, 13];
+%! M = containers.Map (months, vals);
+%! keys = {'Jan', 'Feb'};
+%! assert (M.values, values (M));
+%! assert (M.values (), values (M));
+%! assert (M.values (keys), {10, 11});
+%! assert (M.values (keys)(2), {11});
+%! assert (M.values (keys){2}, 11);
+%!test
+%! months = {'Jan', 'Feb', 'Mar', 'Apr'};
+%! vals = [10, 11, 12, 13];
+%! M = containers.Map (months, vals);
+%! keys = {'Jan', 'FooBar', 'Feb'};
+%! assert (M.isKey (keys)(2:end), logical ([0, 1])); 
+
 ## Test input validation
 %!error containers.Map (1,2,3)
 %!error containers.Map (1,2,3,4,5)