# HG changeset patch # User John W. Eaton # Date 1630527549 14400 # Node ID 55eeb7f0850bc4d3732ee387f87ecefb4fef25cf # Parent d3298a58049ef0eeaf67eaf196e179bc728b5d8f store parent name in function object when caching parents in scope (bug #61105) * symscope.h, symscope.cc (symbol_scope_rep::cache_parent_fcn_names): Also store parent function name in function object. * bug-61105/bug-61105.tst, bug-61105/nested_test_1.m, bug-61105/nested_test_2.m, bug-61105/nested_test_3.m: New test files. * test/bug-61105/module.mk: New file. * test/module.mk: Update. diff -r d3298a58049e -r 55eeb7f0850b libinterp/corefcn/symscope.cc --- a/libinterp/corefcn/symscope.cc Sat Aug 21 15:02:48 2021 +0200 +++ b/libinterp/corefcn/symscope.cc Wed Sep 01 16:19:09 2021 -0400 @@ -197,6 +197,20 @@ } void + symbol_scope_rep::cache_parent_fcn_names (const std::list& names) + { + m_parent_fcn_names = names; + + if (m_code && m_code->is_user_function ()) + { + octave_user_function *fcn + = dynamic_cast (m_code); + + fcn->stash_parent_fcn_name (names.front ()); + } + } + + void symbol_scope_rep::set_parent (const std::shared_ptr& parent) { m_parent = std::weak_ptr (parent); diff -r d3298a58049e -r 55eeb7f0850b libinterp/corefcn/symscope.h --- a/libinterp/corefcn/symscope.h Sat Aug 21 15:02:48 2021 +0200 +++ b/libinterp/corefcn/symscope.h Wed Sep 01 16:19:09 2021 -0400 @@ -262,10 +262,7 @@ return m_parent_fcn_names; } - void cache_parent_fcn_names (const std::list& names) - { - m_parent_fcn_names = names; - } + void cache_parent_fcn_names (const std::list& names); octave_user_code *user_code (void) const { return m_code; } diff -r d3298a58049e -r 55eeb7f0850b test/bug-61105/bug-61105.tst --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/bug-61105/bug-61105.tst Wed Sep 01 16:19:09 2021 -0400 @@ -0,0 +1,32 @@ +######################################################################## +## +## Copyright (C) 2021 The Octave Project Developers +## +## See the file COPYRIGHT.md in the top-level directory of this +## distribution or . +## +## This file is part of Octave. +## +## Octave is free software: you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation, either version 3 of the License, or +## (at your option) any later version. +## +## Octave is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with Octave; see the file COPYING. If not, see +## . +## +######################################################################## + +%!assert (nested_test_1 (2), 24) + +%!assert (nested_test_2 (), 24) + +%!test +%! fh = nested_test_3 (); +%! assert (fh (2), 24); diff -r d3298a58049e -r 55eeb7f0850b test/bug-61105/module.mk --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/bug-61105/module.mk Wed Sep 01 16:19:09 2021 -0400 @@ -0,0 +1,7 @@ +bug_61105_TEST_FILES = \ + %reldir%/bug-61105.tst \ + %reldir%/nested_test_1.m \ + %reldir%/nested_test_2.m \ + %reldir%/nested_test_3.m + +TEST_FILES += $(bug_61105_TEST_FILES) diff -r d3298a58049e -r 55eeb7f0850b test/bug-61105/nested_test_1.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/bug-61105/nested_test_1.m Wed Sep 01 16:19:09 2021 -0400 @@ -0,0 +1,15 @@ +function r = nested_test_1 (val) + a = 3; + b = 5; + c = 7; + function r = f1 (f, x) + r = f(x) + a; + endfunction + function r = f2 (y) + function r2 = f3 (z) + r2 = z^2 + b*y; + endfunction + r = f1 (@f3, y) + c; + endfunction + r = f2 (val); +endfunction diff -r d3298a58049e -r 55eeb7f0850b test/bug-61105/nested_test_2.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/bug-61105/nested_test_2.m Wed Sep 01 16:19:09 2021 -0400 @@ -0,0 +1,8 @@ +function r = nested_test_2 () + a = 3; + b = 5; + c = 7; + f1 = @(f, x) f(x) + a; + f2 = @(y) f1 (@(z) z^2 + b*y, y) + c; + r = f2 (2); +endfunction diff -r d3298a58049e -r 55eeb7f0850b test/bug-61105/nested_test_3.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/bug-61105/nested_test_3.m Wed Sep 01 16:19:09 2021 -0400 @@ -0,0 +1,7 @@ +function fh = nested_test_3 () + a = 3; + b = 5; + c = 7; + f1 = @(f, x) f(x) + a; + fh = @(y) f1 (@(z) z^2 + b*y, y) + c; +endfunction diff -r d3298a58049e -r 55eeb7f0850b test/module.mk --- a/test/module.mk Sat Aug 21 15:02:48 2021 +0200 +++ b/test/module.mk Wed Sep 01 16:19:09 2021 -0400 @@ -91,6 +91,7 @@ include %reldir%/bug-59704/module.mk include %reldir%/bug-59937/module.mk include %reldir%/bug-60237/module.mk +include %reldir%/bug-61105/module.mk include %reldir%/class-concat/module.mk include %reldir%/classdef/module.mk include %reldir%/classdef-multiple-inheritance/module.mk