comparison src/ov-cell.cc @ 10871:333bf09e3b6e

only allow struct assignments to non-struct values for empty arrays
author Jaroslav Hajek <highegg@gmail.com>
date Mon, 09 Aug 2010 09:04:00 +0200
parents 89f4d7e294cc
children 0d9640d755b1
comparison
equal deleted inserted replaced
10870:307c8396bc83 10871:333bf09e3b6e
261 if (is_empty () && type[1] == '.') 261 if (is_empty () && type[1] == '.')
262 { 262 {
263 // Allow conversion of empty cell array to some other 263 // Allow conversion of empty cell array to some other
264 // type in cases like 264 // type in cases like
265 // 265 //
266 // x = []; x(i).f = rhs 266 // x = {}; x(i).f = rhs
267 267
268 octave_value tmp = octave_value::empty_conv (type, rhs); 268 octave_value tmp = octave_value::empty_conv (type, rhs);
269 269
270 return tmp.subsasgn (type, idx, rhs); 270 return tmp.subsasgn (type, idx, rhs);
271 } 271 }
326 } 326 }
327 break; 327 break;
328 328
329 case '.': 329 case '.':
330 { 330 {
331 std::string nm = type_name (); 331 if (is_empty ())
332 error ("%s cannot be indexed with %c", nm.c_str (), type[0]); 332 {
333 // Do nothing; the next branch will handle it.
334 }
335 else
336 {
337 std::string nm = type_name ();
338 error ("%s cannot be indexed with %c", nm.c_str (), type[0]);
339 }
333 } 340 }
334 break; 341 break;
335 342
336 default: 343 default:
337 panic_impossible (); 344 panic_impossible ();
400 } 407 }
401 break; 408 break;
402 409
403 case '.': 410 case '.':
404 { 411 {
405 std::string nm = type_name (); 412 if (is_empty ())
406 error ("%s cannot be indexed with %c", nm.c_str (), type[0]); 413 {
414 // Allow conversion of empty cell array to some other
415 // type in cases like
416 //
417 // x = {}; x.f = rhs
418
419 octave_value tmp = octave_value::empty_conv (type, rhs);
420
421 return tmp.subsasgn (type, idx, rhs);
422 }
423 else
424 {
425 std::string nm = type_name ();
426 error ("%s cannot be indexed with %c", nm.c_str (), type[0]);
427 }
407 } 428 }
408 break; 429 break;
409 430
410 default: 431 default:
411 panic_impossible (); 432 panic_impossible ();