[Bug 274254] The /bin/sh $LINENO value just after a nested function is misleading.

From: <bugzilla-noreply_at_freebsd.org>
Date: Tue, 03 Oct 2023 21:34:28 UTC
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=274254

            Bug ID: 274254
           Summary: The /bin/sh $LINENO value just after a nested function
                    is misleading.
           Product: Base System
           Version: 13.2-RELEASE
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Some People
          Priority: ---
         Component: bin
          Assignee: bugs@FreeBSD.org
          Reporter: white-pack@pm.me

Created attachment 245417
  --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=245417&action=edit
A sample script for inspiring a fix.

The following script reveals the issue

 1  #!/bin/sh
 2
 3  check()
 4  {
 5      echo $1 - \
 6      $(
 7          [ $2 -eq $3 ] \
 8              && echo OK \
 9              || echo FAIL "($2 != $3)"
10      )
11  }
12
13  main()
14  {
15      check 2 $LINENO 3
16
17      inner()
18      {
19          check 4 $LINENO 3
20      }
21
22      check 3 $LINENO 10
23      inner
24  }
25
26  check 1 $LINENO 26
27  main

Here's its output:

1 - OK
2 - OK
3 - FAIL (22 != 10)
4 - OK

Every line of the output should be "OK", but the third one fails.

The internal logic controlling LINENO seems to ignore that inner() was nested.

I attach an ad-hoc "work-around" which could inspire a possible fix.

-- 
You are receiving this mail because:
You are the assignee for the bug.