# HG changeset patch # User John W. Eaton # Date 1594300810 14400 # Node ID ac7ab2a9018e3c86e677131fda0a30d19c6b54ef # Parent 3dae50cf0bc5fd0070f565eb8a75fd755806dd8d create empty c-s list for x.a (bug #58695) * ov-struct.cc (octave_struct::subsref): Create empty comma-separated list if indexing operation creates empty cell array. From Fernando Alvarruiz. diff -r 3dae50cf0bc5 -r ac7ab2a9018e libinterp/octave-value/ov-struct.cc --- a/libinterp/octave-value/ov-struct.cc Thu Jul 09 09:15:58 2020 -0400 +++ b/libinterp/octave-value/ov-struct.cc Thu Jul 09 09:20:10 2020 -0400 @@ -146,6 +146,9 @@ const Cell t = tmp.index (idx.front ()); + // Avoid creating a comma-separated list if the result is a + // single element. + retval(0) = (t.numel () == 1) ? t(0) : octave_value (t, true); // We handled two index elements, so tell @@ -162,8 +165,10 @@ { const Cell t = dotref (idx.front ()); - if (! map.isempty ()) - retval(0) = (t.numel () == 1) ? t(0) : octave_value (t, true); + // Avoid creating a comma-separated list if the result is a + // single element. + + retval(0) = (t.numel () == 1) ? t(0) : octave_value (t, true); } break; @@ -207,6 +212,9 @@ const Cell t = tmp.index (idx.front (), auto_add); + // Avoid creating a comma-separated list if the result is a + // single element. + retval = (t.numel () == 1) ? t(0) : octave_value (t, true); // We handled two index elements, so tell @@ -225,6 +233,9 @@ { const Cell t = dotref (idx.front (), auto_add); + // Avoid creating a comma-separated list if the result is a + // single element. + retval = (t.numel () == 1) ? t(0) : octave_value (t, true); } }