Need help understanding Matlab behavior

Output for first version of mkfh.m in Matlab R2021a:

>> test_mkfh

fh =

  function_handle with value:

    @mkfh/f2


ans =

    24


info = 

  struct with fields:

     function: 'mkfh/f2'
         type: 'nested'
         file: '/home/siko1056/Downloads/mkfh.m'
    workspace: {[1×1 struct]}


ans =

  1×1 cell array

    {1×1 struct}

>> ans{:}

ans = 

  struct with fields:

    fh: @mkfh/f2
     a: 3
     b: 5
     c: 7

>> info.workspace{:}

ans = 

  struct with fields:

    fh: @mkfh/f2
     a: 3
     b: 5
     c: 7

and for the second version:

>> test_mkfh

fh =

  function_handle with value:

    @(y)f1(@(z)z^2+b*y,y)+c


ans =

    24


info = 

  struct with fields:

            function: '@(y)f1(@(z)z^2+b*y,y)+c'
                type: 'anonymous'
                file: '/home/siko1056/Downloads/mkfh.m'
           workspace: {[1×1 struct]}
    within_file_path: ''


ans =

  1×1 cell array

    {1×1 struct}

>> ans{:}

ans = 

  struct with fields:

    f1: @(f,x)f(x)+a
     b: 5
     c: 7

>> info.workspace{:}

ans = 

  struct with fields:

    f1: @(f,x)f(x)+a
     b: 5
     c: 7

Thanks for the info.

While I was trying to remove the added_static attribute and associated functions in the symbol_record class (see also: Prefer enum over static const names? - #4 by jwe) I stumbled across a bug with anonymous functions handles that lead to some confusion about exactly how things are supposed to work.

It appears that at some point, possibly when I was working on GNU Octave - Bugs: bug #60845, Variables in nested functions... [Savannah], I broke something related to setting parent stack frames for nested functions in some cases. It looks like it’s related to incorrectly setting the parent for a nested function. While investigating this problem, I also found that we are storing info about parent functions directly in the function object and also in the scope object that the function contains. Ugh! Someone should probably fix that since storing the same info in multiple places almost always leads to trouble. This mess is almost certainly my work, so I’ll see if I can fix it.