declare -F incorrect line number

2022-10-02 Thread Daniel Castro


   Configuration Information [Automatically generated, do not change]:

   Machine: x86_64

   OS: linux-gnu

   Compiler: gcc

   Compilation CFLAGS: -g -O2
   -fdebug-prefix-map=/build/bash-Smvct5/bash-5.0=.
   -fstack-protector-strong -Wformat -Werror=format-security -Wall
   -Wno-parentheses -Wno-format-security

   uname output: Linux danicc097 5.4.0-126-generic #142-Ubuntu SMP Fri Aug
   26 12:12:57 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

   Machine Type: x86_64-pc-linux-gnu


   Bash Version: 5.0

   Patch Level: 17

   Release Status: release


   Description:

 declare -F yields the wrong line number for a function that has
   nested functions declared within. Instead it gives the line number of
   the last nested function.


   Repeat-By:

 ```

 #!/bin/bash


   set -e


   fn-a() {

 echo "..."

 echo "..."

 echo "..."


 nested-fn() {

   :

 }


 nested-fn2() {

   :

 }


 nested-fn

   }


   shopt -s extdebug

   ln="$(declare -F fn-a)"

   shopt -u extdebug


   echo "$ln" # fn-a 14, should be 5


 ```

   Fix:

   [Description of how to fix the problem.  If you don't know a

   fix for the problem, don't include this section.]


RE: declare -F incorrect line number

2022-10-05 Thread Daniel Castro
   In this case I’m not doing anything too fancy: my use case is I have a
   main project script where I declare functions that can get executed
   independently with some prefix: e.g. ``x.build()``, ``x.test()`` so I
   can call ``myscript test`` or ``myscript build`` by parsing all x.*
   functions, and sometimes I have functions within them just for clarity
   since they’re just some abstraction for that particular function logic.

   I parse these x function's comments as well to show in ``--help`` and
   therefore happened to notice the bug. The workaround for me is to
   simply  move them outside the top level function, but I don't know if
   it would get in the way for some people doing more convoluted stuff
   with functions.


   From: [1]Chet Ramey
   Sent: Wednesday, 5 October 2022 20:22
   To: [2]Daniel Castro; [3]bug-bash@gnu.org
   Cc: [4]chet.ra...@case.edu
   Subject: Re: declare -F incorrect line number


   On 10/2/22 4:51 AM, Daniel Castro wrote:


   > Bash Version: 5.0

   >

   > Patch Level: 17

   >

   > Release Status: release

   >

   >

   > Description:

   >

   >   declare -F yields the wrong line number for a function that has

   > nested functions declared within. Instead it gives the line
   number of

   > the last nested function.


   Thanks for the report. I'll take a look, but I have a question. Why are
   you

   declaring functions inside functions? Are you trying to do some kind of

   conditional definition?


   Chet


   --

   ``The lyf so short, the craft so long to lerne.'' - Chaucer

 ``Ars longa, vita brevis'' - Hippocrates

   Chet Ramey, UTech, CWRUc...@case.edu
   http://tiswww.cwru.edu/~chet/

References

   1. mailto:chet.ra...@case.edu
   2. mailto:danicc...@gmail.com
   3. mailto:bug-bash@gnu.org
   4. mailto:chet.ra...@case.edu