Repository navigation
[word_eval] Implement 'shopt -s compat_array'. - #728
Conversation
andychu
left a comment
There was a problem hiding this comment.
Great thanks for doing this!
It doesn't look like too big a change which I'm happy about.
| if val.tag_() in (value_e.MaybeStrArray, value_e.AssocArray) and lval.tag_() == lvalue_e.Named: | ||
| named_lval = cast(lvalue__Named, lval) | ||
| if word_eval.CheckCompatArray(named_lval.name, self.exec_opts): | ||
| val = word_eval.ResolveCompatArray(val) |
There was a problem hiding this comment.
Would this part be made obsolete if we made BASH_LINENO etc. immutable?
I guess that would make Oil technically incompatible, but I've been thinking about that. Also it makes sense to tighten up things like PATH=(a b c) and HOME=(a b c) (they shouldn't be arrays)
This doesn't have to be done in this commit; I'm just curious / brainstorming the semantics
There was a problem hiding this comment.
As you have already written in another comment, this change also affects the other mutable variables when shopt -s compat_array is set.
| # For compatibility, ${BASH_SOURCE} and ${BASH_SOURCE[@]} are both valid. | ||
| # ${FUNCNAME} and ${BASH_LINENO} are also the same type of of special variables. | ||
| _STRING_AND_ARRAY = ['BASH_SOURCE', 'FUNCNAME', 'BASH_LINENO'] | ||
| def CheckCompatArray(var_name, opts, compat_introspect=True): |
There was a problem hiding this comment.
I would name compat_introspect something more descriptive like is_plain_var or is_plain_var_sub
( The difference between SimpleVarSub and BracedVarSub is one thing I want to get rid of with #604 )
There was a problem hiding this comment.
I renamed it to is_plain_var_sub b311fb3.
|
Ah never mind about my lvalue comment. I think this works now? If so then I think we should add things like that as test cases. I don't think the tests are hitting some code paths. |
I added a test case 4662002 to find that it actually doesn't work. Currently, it mutates the array to a scalar. I'll fix it later. |
5ab54ad to
b311fb3
Compare
andychu
left a comment
There was a problem hiding this comment.
OK I think the continuous build might fail but let's see what happens ... e.g. the test/spec.sh numbers should generally be adjusted to keep it green.
| case ${SH##*/} in (osh) shopt -s compat_array;; esac | ||
| case ${SH##*/} in (zsh) setopt KSH_ARRAYS;; esac | ||
| arr=(foo bar baz) | ||
| echo "$arr" |
There was a problem hiding this comment.
I think this should also test ${arr} since that's a different code path. (as mentioned I want to collapse those)
There was a problem hiding this comment.
I added the test for ${arr} in another PR #733.
|
Oh I also had that other comment about testing In any case I'm interested to see what works in ble.sh is, so if there is something I can try let me know. Should I just switch to the We can put instructions here too: https://github.com/oilshell/oil/wiki/Running-ble.sh-With-Oil |
|
Oh, you have already merged it. Thank you!
I have actually fixed it now. I'll submit it in another PR.
Yes, now it is ready so I'm going to prepare something that can be tried out.
OK. |
I added a description in the Wiki page. You can follow the instructions Update ble.osh and Try |
Ref #726
Implement
shopt -s compat_arrayto allow$array(Test bf9f332, Fix 6704770)Disallow
${#BASH_SOURCE},${BASH_SOURCE:1:1},${BASH_SOURCE#X},${BASH_SOURCE-X}, etc. by default (Fix b1a16c2). In this implementation, everything with additional suffix/prefix are disallowed.