-
-
Notifications
You must be signed in to change notification settings - Fork 162
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] Implement ${a[@]@P}
and make ${a[@]@a}
and ${a[@]@Q}
consistent with Bash
#2210
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! It looks like there are a few type errors, which can be checked with
devtools/types.sh check-oils
See log at the end here:
http://op.oilshell.org/uuu/github-jobs/8824/cpp-coverage.wwz/_tmp/soil/logs/compare-gcc-clang.txt
Happy New Year!
9634100
to
0a18208
Compare
I fixed type annotations in (Please ignore this. I found the description in mycpp/README.md)However, I got the following C++ compilation error: _gen/bin/oils_for_unix.mycpp.cc: In member function ‘BigStr* prompt::Evaluator::EvalFirstPrompt()’:
_gen/bin/oils_for_unix.mycpp.cc:41915:34: error: ‘class value_asdl::value_t’ has no member named ‘s’
41915 | return this->EvalPrompt(val->s);
| ^ The corresponding Python code is this: Lines 303 to 305 in 0a18208
Why is edit: I found an answer in mycpp/README.md: Lines 253 to 259 in f2c84da
Happy New Year! |
0a18208
to
c38fa23
Compare
(Resolved)
I thought you once told me that ps1_val = this->mem->env_config->GetVal(S_Eni);
if (ps1_val->tag() == value_e::Str) {
val = static_cast<value::Str*>(ps1_val);
return this->EvalPrompt(val->s);
}
else {
return S_Aoo;
} where Anyway, I decided to use the convention of |
c38fa23
to
8e8271e
Compare
I updated tests because now OSH implements the expected behavior: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for doing this, a couple questions ....
spec/var-op-bash.test.sh
Outdated
a $'b\\nc' | ||
status=0 | ||
a | ||
a a a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can see that OSH differs from bash because of a quoting difference, which is OK
But it also seems to differ with a a a
vs. ''
?
Or maybe that is addressed in a follow-up?
TBH I don't understand the reasons for the evaluation logic - in these cases, my review falls back to "does OSH match bash?"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah! Thanks for pointing out this. This is just my oversight. OSH should generate the same result as Bash. Let me think about how we should distinguish array-origin BashArray from $@
-origin BashArray.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is OK if we fix that later (or even not at all if nobody runs into it, and if bash does not document it)
Sometimes when I encounter a quirk like this, I split it into a separate test case, and then mark it oils_failures_allowed += 1
That is just a "note for later" (Basically because there seem to be infinite bash implementation details! I think using @
with a type query is EXTREMELY obscure. I will be surprised if anyone depends on this)
So that way the first test case have bash STDOUT === osh STDOUT, which is a nice proprety
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you wait for a while? If it turns out to be easy to fix, I can fix it within this PR. If not, I'll handle it in a separate PR later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I decided to defer it. The best solution could be to introduce a new type to represent the list coming from $@
, but one might relate it to the forthcoming switching from BashArray to SparseArray. We can discuss that later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now this is an allowed OSH failure: fda3cd4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK sounds good! I made a comment about minimizing "OK bash" blocks when our intention is to agree with bash, but this is a matter of judgement
There will always be some of these, but IMO it is easier to maintain later if we don't have to read and edit the large assertion blocks, because it's easy to make mistakes, i.e. copy/paste bugs where we didn't actually fix things
This corresponds to PR(b) explained in #2201.
The behavior for
@a
${a@a}
and${a[0]@A}
#2208,${a[@]@a}
generatesa a ... a
andA A ... A
for indexed andassociative arrays, respectively.
${a@a}
and${a[0]@A}
#2208,${a[@]@a}
generates single wordsa
andA
for indexed andassociative arrays, respectively, because osh returns the type of the entire array.
Others
This PR also includes the modification to
@Q
. Also,@P
was only supported for a scalar variable, but now this PR implements it for BashArray/BashAssoc. 03cf713 is a related refactoring commit.