changeset 20640:f9c991dc5c1a

avoid scope error in anonymous functions (bug #45835) * ov-fcn-handle.cc (octave_fcn_binder::maybe_binder): Don't optimize functions that wrap eval or feval.
author John W. Eaton <jwe@octave.org>
date Sun, 11 Oct 2015 18:53:05 -0400
parents a260a6acb70f
children c3c052b9192a
files libinterp/octave-value/ov-fcn-handle.cc
diffstat 1 files changed, 26 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/octave-value/ov-fcn-handle.cc	Sun Oct 11 23:09:01 2015 +0200
+++ b/libinterp/octave-value/ov-fcn-handle.cc	Sun Oct 11 18:53:05 2015 -0400
@@ -2066,29 +2066,32 @@
                     {
                       // It's a name.
                       std::string head_name = head_id->name ();
-                      // Function handles can't handle legacy dispatch, so
-                      // we make sure it's not defined.
-                      if (symbol_table::get_dispatch (head_name).size () > 0)
+
+                      if (head_name == "eval" || head_name == "feval")
                         bad = true;
                       else
                         {
-                          // Simulate try/catch.
-                          unwind_protect frame;
-                          interpreter_try (frame);
+                          // Function handles can't handle legacy
+                          // dispatch, so we make sure it's not
+                          // defined.
 
-                          bool execution_error = false;
-
-                          try
+                          if (symbol_table::get_dispatch (head_name).size () > 0)
+                            bad = true;
+                          else
                             {
-                              root_val = make_fcn_handle (head_name);
+                              // Simulate try/catch.
+                              unwind_protect frame;
+                              interpreter_try (frame);
+
+                              try
+                                {
+                                  root_val = make_fcn_handle (head_name);
+                                }
+                              catch (const octave_execution_exception&)
+                                {
+                                  bad = true;
+                                }
                             }
-                          catch (const octave_execution_exception&)
-                            {
-                              execution_error = true;
-                            }
-
-                          if (execution_error)
-                            bad = true;
                         }
                     }
                 }
@@ -2113,6 +2116,12 @@
   return retval;
 }
 
+/*
+%!test
+%! f = @(t) eval ('2*t');
+%! assert (f (21), 42);
+*/
+
 octave_value_list
 octave_fcn_binder::do_multi_index_op (int nargout,
                                       const octave_value_list& args)