-
-
Notifications
You must be signed in to change notification settings - Fork 183
Open
Labels
Description
From Alexey Shamrin on Zulip (#oils-discuss > Segmentation fault in evalHay after some syntax errors),
Seems like a bug:
$ cat crash.hay echo = $ cat crash.ysh const h = parseHay('crash.hay') const result = evalHay(h) $ ysh --version Oils 0.37.0 https://oils.pub/ git commit = a9e1764bc62097e63e385a631a476c04bce534e8 $ ysh crash.ysh echo = ^ crash.hay:1: Unexpected = (Hint: use var/setvar, or quote it) Segmentation fault
When run in a python build we see the AssertionError:
ysh-0.37$ = parseHay('crash.hay')
echo =
^
crash.hay:1: Unexpected = (Hint: use var/setvar, or quote it)
Traceback (most recent call last):
File "/home/aolse/oils/oil/bin/oils_for_unix.py", line 263, in <module>
sys.exit(main(sys.argv))
File "/home/aolse/oils/oil/bin/oils_for_unix.py", line 232, in main
return AppBundleMain(argv)
File "/home/aolse/oils/oil/bin/oils_for_unix.py", line 186, in AppBundleMain
return shell.Main(lang, arg_r, environ, login_shell, loader, readline)
File "/home/aolse/oils/oil/core/shell.py", line 1214, in Main
prompt_plugin, waiter, errfmt)
File "/home/aolse/oils/oil/core/main_loop.py", line 280, in Interactive
is_return, _ = cmd_ev.ExecuteAndCatch(node, 0)
File "/home/aolse/oils/oil/osh/cmd_eval.py", line 2366, in ExecuteAndCatch
status = self._Execute(node)
File "/home/aolse/oils/oil/osh/cmd_eval.py", line 2164, in _Execute
status = self._Dispatch(node, cmd_st)
File "/home/aolse/oils/oil/osh/cmd_eval.py", line 1975, in _Dispatch
status = self._DoExpr(node)
File "/home/aolse/oils/oil/osh/cmd_eval.py", line 1291, in _DoExpr
ui.PrettyPrintValue('', val, mylib.Stdout())
File "/home/aolse/oils/oil/display/ui.py", line 582, in PrettyPrintValue
if TypeNotPrinted(val):
File "/home/aolse/oils/oil/display/ui.py", line 556, in TypeNotPrinted
return val.tag() in (value_e.Null, value_e.Bool, value_e.Int,
AttributeError: 'NoneType' object has no attribute 'tag'
The root cause is that we return None in func_hay.ParseHay on a parse error:
Lines 66 to 71 in 16ef54b
| try: | |
| with alloc.ctx_SourceCode(arena, src): | |
| node = main_loop.ParseWholeFile(c_parser) | |
| except error.Parse as e: | |
| self.errfmt.PrettyPrintError(e) | |
| return None |
There are two possible fixes:
- We return
value.Null, - We raise an
error.ExprfromparseHay
I think (2) is best.
Reactions are currently unavailable