# HG changeset patch # User Lachlan Andrew # Date 1450228199 -39600 # Node ID 99d373870017255e86fc167251ef7a12c15484fb # Parent 87b3348d8d76a4cbf63d2829750d3ebeb998756f Fix assigning to trailing singletons for structs and cell (bug #39789, bug #35841) * Array.cc (index (Array ia, bool, T)): Only return empty array if resized dimension mismatches ia. * ov-struct.cc (subsasgn): Remove workaround for index(_,_,_) returning an empty array for trailing singletons introduced to solve bug #35841. * index.tst: Add tests for bug #35841, #39789. diff -r 87b3348d8d76 -r 99d373870017 libinterp/octave-value/ov-struct.cc --- a/libinterp/octave-value/ov-struct.cc Tue Dec 15 21:30:25 2015 +1100 +++ b/libinterp/octave-value/ov-struct.cc Wed Dec 16 12:09:59 2015 +1100 @@ -317,10 +317,6 @@ { map.contents (pkey).make_unique (); tmpc = map.contents (pkey).index (idx.front (), true); - // See bug #35841, assigning to struct with trailing - // singleton dimensions. - if (tmpc.is_empty ()) - tmpc = Cell (1,1); } // FIXME: better code reuse? @@ -455,8 +451,7 @@ const_cast (map); // cast to const reference, avoid forced key insertion. if (idxf.all_scalars () - || cmap.contents (key).index (idxf, true).numel () - <= 1) + || cmap.contents (key).index (idxf, true).numel () == 1) { map.assign (idxf, key, Cell (t_rhs.storable_value ())); diff -r 87b3348d8d76 -r 99d373870017 liboctave/array/Array.cc --- a/liboctave/array/Array.cc Tue Dec 15 21:30:25 2015 +1100 +++ b/liboctave/array/Array.cc Wed Dec 16 12:09:59 2015 +1100 @@ -1115,7 +1115,8 @@ int ial = ia.numel (); dim_vector dv = dimensions.redim (ial); dim_vector dvx = dim_vector::alloc (ial); - for (int i = 0; i < ial; i++) dvx(i) = ia(i).extent (dv(i)); + for (int i = 0; i < ial; i++) + dvx(i) = ia(i).extent (dv(i)); if (! (dvx == dv)) { bool all_scalars = true; @@ -1125,10 +1126,10 @@ return Array (dim_vector (1, 1), rfv); else tmp.resize (dvx, rfv); + + if (tmp.dimensions != dvx) + return Array (); } - - if (tmp.dimensions != dvx) - return Array (); } return tmp.index (ia); diff -r 87b3348d8d76 -r 99d373870017 test/index.tst --- a/test/index.tst Tue Dec 15 21:30:25 2015 +1100 +++ b/test/index.tst Wed Dec 16 12:09:59 2015 +1100 @@ -576,3 +576,13 @@ %!error abc(1+0.5*i,3) %!error abc(2,0-2*i) +## bug #35841 +%!test +%! a(1,1,1).b(1) = 2; +%! a(1,1,1).b(1) = 3; + +## bug #39789 +%!test +%! c = cell(1,1,1); +%! c{1,1,1} = zeros(5, 2); +%! c{1,1,1}(:, 1) = 1;