]> git.ipfire.org Git - thirdparty/bash.git/blobdiff - builtins/declare.def
commit bash-20121005 snapshot
[thirdparty/bash.git] / builtins / declare.def
index a8ea9483397f3b07562304a3d0a2ec1c725dcb4f..2fec6066f116f5897b5b255f3ce5d59a2b783f8e 100644 (file)
@@ -301,6 +301,24 @@ declare_internal (list, local_var)
       else
        value = "";
 
+      /* Do some lexical error checking on the LHS and RHS of the assignment
+        that is specific to nameref variables. */
+      if (flags_on & att_nameref)
+       {
+         if (valid_array_reference (name))
+           {
+             builtin_error (_("%s: reference variable cannot be an array"), name);
+             assign_error++;
+             NEXT_VARIABLE ();
+           }
+         else if (STREQ (name, value))
+           {
+             builtin_error (_("%s: nameref variable self references not allowed"), name);
+             assign_error++;
+             NEXT_VARIABLE ();
+           }
+       }
+
 #if defined (ARRAY_VARS)
       compound_array_assign = simple_array_assign = 0;
       subscript_start = (char *)NULL;
@@ -493,6 +511,13 @@ declare_internal (list, local_var)
                  VSETATTR (var, att_invisible);
                }
            }
+         /* Can't take an existing array variable and make it a nameref */
+         else if ((array_p (var) || assoc_p (var)) && (flags_on & att_nameref))
+           {
+             builtin_error (_("%s: reference variable cannot be an array"), name);
+             assign_error++;
+             NEXT_VARIABLE ();
+           }
 
          /* Cannot use declare +r to turn off readonly attribute. */ 
          if (readonly_p (var) && (flags_off & att_readonly))