diff 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
line wrap: on
line diff
--- a/src/ov-cell.cc	Sun Aug 08 21:23:39 2010 -0700
+++ b/src/ov-cell.cc	Mon Aug 09 09:04:00 2010 +0200
@@ -263,7 +263,7 @@
                 // Allow conversion of empty cell array to some other
                 // type in cases like
                 //
-                //  x = []; x(i).f = rhs
+                //  x = {}; x(i).f = rhs
 
                 octave_value tmp = octave_value::empty_conv (type, rhs);
 
@@ -328,8 +328,15 @@
 
         case '.':
           {
-            std::string nm = type_name ();
-            error ("%s cannot be indexed with %c", nm.c_str (), type[0]);
+            if (is_empty ())
+              {
+                // Do nothing; the next branch will handle it.
+              }
+            else
+              {
+                std::string nm = type_name ();
+                error ("%s cannot be indexed with %c", nm.c_str (), type[0]);
+              }
           }
           break;
 
@@ -402,8 +409,22 @@
 
         case '.':
           {
-            std::string nm = type_name ();
-            error ("%s cannot be indexed with %c", nm.c_str (), type[0]);
+            if (is_empty ())
+              {
+                // Allow conversion of empty cell array to some other
+                // type in cases like
+                //
+                //  x = {}; x.f = rhs
+
+                octave_value tmp = octave_value::empty_conv (type, rhs);
+
+                return tmp.subsasgn (type, idx, rhs);
+              }
+            else
+              {
+                std::string nm = type_name ();
+                error ("%s cannot be indexed with %c", nm.c_str (), type[0]);
+              }
           }
           break;