changeset 5609:bf96b0f9dbd7

[project @ 2006-02-09 02:29:59 by jwe]
author jwe
date Thu, 09 Feb 2006 02:30:00 +0000
parents 320be6d5e027
children 9761b7d24e9e
files src/ChangeLog src/parse.y
diffstat 2 files changed, 29 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Wed Feb 08 20:28:18 2006 +0000
+++ b/src/ChangeLog	Thu Feb 09 02:30:00 2006 +0000
@@ -1,3 +1,10 @@
+2006-02-08  John W. Eaton  <jwe@octave.org>
+
+	* parse.y (frob_function): Clear ID_NAME from top_level symbol
+	table if we are defining a function at the top-level and a
+	function with the same name is already in the top-level symbol
+	table.
+
 2006-01-31  John W. Eaton  <jwe@octave.org>
 
 	* ov-base-sparse.h (octave_base_sparse<T>::nzmax): New function.
--- a/src/parse.y	Wed Feb 08 20:28:18 2006 +0000
+++ b/src/parse.y	Thu Feb 09 02:30:00 2006 +0000
@@ -2572,6 +2572,28 @@
 
   curr_sym_tab->clear (id_name);
 
+  if (! lexer_flags.parsing_nested_function
+      && symtab_context.top () == top_level_sym_tab)
+    {
+      symbol_record *sr = top_level_sym_tab->lookup (id_name);
+
+      // Only clear the existing name if it is already defined as a
+      // function.  If there is already a variable defined with the
+      // same name as a the current function, it will continue to
+      // shadow this name until the variable is cleared.  This means
+      // that for something like the following at the command line,
+      //
+      //   f = 13;
+      //   function f () 7, end
+      //   f
+      //
+      // F will still refer to the variable F (with value 13) rather
+      // than the function F, until the variable F is cleared.
+
+      if (sr && sr->is_function ())
+	top_level_sym_tab->clear (id_name);
+    }
+
   symbol_record *sr = fbi_sym_tab->lookup (id_name, true);
 
   if (sr)