Skip to content

Commit 24146f4

Browse files
author
Andy C
committed
[osh] Disable partially broken check for parsing options in functions
- For ble.sh compatibility with shopt -u expand_aliases - #1069 - the check worked in shell functions, but was broken in proc/func
1 parent bc8ff52 commit 24146f4

File tree

4 files changed

+38
-11
lines changed

4 files changed

+38
-11
lines changed

core/state.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -466,10 +466,18 @@ def set_emacs(self):
466466

467467
def _SetArrayByNum(self, opt_num, b):
468468
# type: (int, bool) -> None
469+
"""
470+
Disabled check: ParsingChangesAllowed() worked for shell functions, but
471+
was broken for proc and func. Because they don't use the argv stack.
472+
473+
It also doesn't work for 'eval' and 'source', as shown by ble.sh.
474+
(Although source inside a function is an odd usage.)
475+
469476
if (opt_num in consts.PARSE_OPTION_NUMS and
470477
not self.mem.ParsingChangesAllowed()):
471478
e_die('Syntax options must be set at the top level '
472479
'(outside any function)')
480+
"""
473481

474482
self._Set(opt_num, b)
475483

@@ -1335,15 +1343,6 @@ def SetPwd(self, pwd):
13351343
"""Used by builtins."""
13361344
self.pwd = pwd
13371345

1338-
def ParsingChangesAllowed(self):
1339-
# type: () -> bool
1340-
"""For checking that syntax options are only used at the top level."""
1341-
1342-
# DISALLOW proc calls : they push argv_stack, var_stack, debug_stack
1343-
# ALLOW source foo.sh arg1: pushes argv_stack, debug_stack
1344-
# ALLOW FOO=bar : pushes var_stack
1345-
return len(self.var_stack) == 1 or len(self.argv_stack) == 1
1346-
13471346
def Dump(self):
13481347
# type: () -> Tuple[List[value_t], List[value_t], List[value_t]]
13491348
"""Copy state before unwinding the stack."""

soil/worker.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,13 +368,15 @@ dump-env soil/diagnose.sh dump-env -
368368
py-all build/py.sh all -
369369
ble-clone test/ble.sh clone -
370370
ble-build test/ble.sh build -
371-
ble-bash-suite test/ble.sh bash-suite -
372371
ble-test-osh-py test/ble.sh run-tests-osh-py -
373372
wait-for-tarball soil/wait.sh for-cpp-tarball -
374373
test-tar devtools/release-native.sh test-tar -
375374
ble-test-osh-cpp test/ble.sh run-tests-osh-cpp -
376375
EOF
377376

377+
# 2025-02 - times out after 15 minutes? This is just bash, not OSH?
378+
# ble-bash-suite test/ble.sh bash-suite -
379+
378380
# This doesn't work
379381
# ble-test-osh-bash test/ble.sh run-tests-osh-bash -
380382
}

spec/ble-idioms.test.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,3 +269,23 @@ echo "${a[@]}"
269269

270270
## N-I mksh/ash STDOUT:
271271
## END
272+
273+
#### shopt -u expand_aliases and eval
274+
case $SH in zsh|mksh|ash) exit ;; esac
275+
276+
alias echo=false
277+
278+
function f {
279+
shopt -u expand_aliases
280+
eval -- "$1"
281+
shopt -s expand_aliases
282+
}
283+
284+
f 'echo hello'
285+
286+
## STDOUT:
287+
hello
288+
## END
289+
## N-I zsh/mksh/ash STDOUT:
290+
## END
291+

spec/ysh-options.test.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
## oils_failures_allowed: 1
2+
13
# Test shell execution options.
24

35
#### simple_word_eval doesn't split, glob, or elide empty
@@ -75,7 +77,11 @@ argv.py @words
7577
['a', 'b c']
7678
## END
7779

78-
#### parse_at can't be used outside top level
80+
#### DISABLED: parse_at can't be used outside top level
81+
82+
# shopt -u expand_aliases conflicted with ble.sh, and it was also broken for
83+
# proc/func
84+
7985
f() {
8086
shopt -s parse_at
8187
echo status=$?

0 commit comments

Comments
 (0)