-
-
Notifications
You must be signed in to change notification settings - Fork 163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow scalar form of BASH_LINENO and FUNCNAME #656
Allow scalar form of BASH_LINENO and FUNCNAME #656
Conversation
ba41d4a
to
bfc03fe
Compare
Great thank you for fixing this! And with great tests. I don't see what you mean about a bash/Oil difference -- wouldn't the tests fail if that were the case? The test format has the ability to express those differences with
|
Oh I see test case #2 does fail in bash... let me see why that is. |
I moved it to case #1 to make the difference more clear. http://www.oilshell.org/git-branch/dev/andy-21/c156b72b/spec/introspect.html c156b72 (sorry for unrelated changes) To me this feels like a bash bug because it breaks an invariant. Shouldn't (If I remove |
Bash consistently produces the empty value for both # test1.sh
set1=unset set2=unset
[[ ${FUNCNAME+set} ]] && set1=set
[[ ${FUNCNAME[0]+set} ]] && set2=set
echo "\$FUNCNAME = '$FUNCNAME' ($set1)"
echo "\${FUNCNAME[0]} = '${FUNCNAME[0]}' ($set2)"
declare -p FUNCNAME $ bash -c 'source test1.sh'
$FUNCNAME = '' (unset)
${FUNCNAME[0]} = '' (unset)
declare -a FUNCNAME |
Yes bash 4.4 produces https://github.com/oilshell/oil/blob/master/spec/introspect.test.sh#L60 Hopefully it's not too hard to read. But I claim bash's output in lines 91-94 for Well in the other change you're showing that |
Ah.. OK, Bash sets $ bash -c '. test1.sh; f() { . test1.sh; }; f'
$FUNCNAME = '' (unset)
${FUNCNAME[0]} = '' (unset)
declare -a FUNCNAME
$FUNCNAME = 'source' (set)
${FUNCNAME[0]} = 'source' (set)
declare -a FUNCNAME=([0]="source" [1]="f") I remembered it just now, but
|
Ah OK thanks. I see that it's documented but I don't see the rationale for the behavior! I think there could be a different way to test if it's sourced as function scope... I have seen that issue before but I don't recall exactly where. |
Related to the second point in #653 (comment). I found that
BASH_SOURCE
is specially treated (de92fc5).BASH_LINENO
andFUNCNAME
are also members of the same family. They are original scalar variables and later extended to an array variable. They should allow both form of$X
and${X[0]}
.Note: When I create a test, I noticed that there is a difference between Bash and Oil for
FUNCNAME
in source contexts, i.e.,FUNCNAME=
in Bash andFUNCNAME=source
in Oil. The added test is created for the Oil behavior.