-
-
Notifications
You must be signed in to change notification settings - Fork 164
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
[osh] Fix ${unset_variable@Q}
wrongly producing ''
#2186
Conversation
OK, this is probably one of those judgement calls I made, and we should probably roll it back to be more compatible with bash However I also wonder if bash ever documented that empty string produces would bash ever change this? I guess it sorta makes sense if you want to do
in that case empty string can be useful I am wondering if there is any rationale for having a It might be useful for us to document it in |
OK I looked at the code more ... The thing that bugs me about this is that it is clearly a special case ? we have a special boolean only for the I guess the problem is we do There is this I remember this word eval code is very hairy (and I think it is also the biggest file in the bash codebase) I think this change is a good idea, but I want to see if we can do it by transforming |
I added commit a898e4a.
Actually, there are many boolean switches as you mentioned below for
Yes. I actually think we should call
I can try that later, though it might be in the next weekend if it turns out to require larger changes. |
Yeah I think perhaps calling Also there is this old idea I realized the code can be made simpler and faster by doing some stuff at parse time, i.e. to "reorder" the ops inside But I guess we shouldn't bother with that yet, for this relatively small change (although maybe making those decisions faster is not that big a win, because our profiles tend to show GC and memory allocation as the slower things. We are creating many |
I tried to refactor the calls of Importing in
|
# import from frontend/syntax.asdl | |
use frontend syntax { | |
loc Token | |
expr word command |
The problem is that, at the beginning of the generated _devbuild/gen/runtime_asdl.py
, the import
's are conditioned by if TYPE_CHECKING
:
if TYPE_CHECKING:
from _devbuild.gen.syntax_asdl import loc_t, Token, expr_t, word_t, command_t, CompoundWord, DoubleQuoted, ArgList, re_t, redir_loc_t, proc_sig_t, Func
from _devbuild.gen.value_asdl import value_t, Obj
Even with core/runtime.asdl
in the master branch, the same error happens when one tries to call AssignArg.CreateNull()
. The problem has not happened so far just because AssignArg.CreateNull()
hasn't been used in the codebase.
I think the generation of _devbuild/gen/runtime_asdl.py
should be fixed by either removing the condition if TYPE_CHECKING
or modifying the generated CreateNull()
(if it's possible).
Array attributes
$ bash -c 'a=(1 2 3); printf "<%s>\\n" "${a[@]@a}"'
<a>
<a>
<a>
$ bin/osh -c 'a=(1 2 3); printf "<%s>\\n" "${a[@]@a}"'
<a>
The behavior of OSH differs from that of Bash.
The current OSH behavior makes the processing of variable substitutions non-trivial because one needs to know a[@]
should be treated as a single entity at the point of processing a[@]
; i.e., a[@]
and @a
are not orthogonal in the current OSH behavior. Do I need to keep the current OSH behavior?
Namerefs for array elements do not work
$ bash -c 'declare -n ref="a[@]"; a=(1 2 3); printf "<%s>\\n" "$ref"'
<1>
<2>
<3>
$ bash -c 'declare -n ref="a[0]"; a=(1 2 3); printf "<%s>\\n" "$ref"'
<1>
$ bash -c 'declare -n ref="a"; a=(1 2 3); printf "<%s>\\n" "$ref"'
<1>
$ bin/osh -c 'declare -n ref="a[@]"; a=(1 2 3); printf "<%s>\\n" "$ref"'
<a[@]>
$ bin/osh -c 'declare -n ref="a[0]"; a=(1 2 3); printf "<%s>\\n" "$ref"'
<a[0]>
$ bin/osh -c 'declare -n ref="a"; a=(1 2 3); printf "<%s>\\n" "$ref"'
<1>
OSH just returns the string for the name references of the form a[...]
. What is the intended behavior in OSH? In particular, the first case is tricky, and we need to reconsider the array processing in variable substitutions if we would support it.
I only did the minimal things to make a few shell scripts work, and make additional tests pass In general if something does not work for nameref, However I still want to think about the bash behavior here ... Thanks for documenting it in OSH The problem is that I am not confident bash doesn't change this behavior later If you turn on i.e. bash has changed over time and presumably broken existing scripts |
namerefs are another feature of bash that I don't really think is well-specified or documented It seems like mostly an accident of the implementation to me |
OK I reproduced the ASDL bug you're talking about, thank you for noticing that! |
OK I fixed the ASDL bug Python 2 has an issue where sometimes you have to do |
OK I simplified the logic like this:
then change the test to
and then for I also added a test to show that some other ops in bash behave the same way, like Thanks for finding this issue! |
Thank you!
This change breaks |
Ahh we are missing test coverage for |
As I mentioned, in my local repository, I already have commits to fix everything by refactoring the calls of |
Ah OK, yes definitely feel free to fix it along with the other issues! |
#2185 (comment)
The current
master
produces''
for unset variables with the construct${var@Q}
.This PR fixes
${var@Q}
so that it produces no quoted words for unset variables.Note: There was a test case with
OK osh STDOUT
that explicitly requires''
for unset variables, but I removed the OK section so that it requires the behavior to match Bash.