From 6631385b46dbdc4ee5806e22fe3ea573658cb9d9 Mon Sep 17 00:00:00 2001 From: Andy Chu Date: Mon, 11 Jan 2021 00:07:37 -0800 Subject: [PATCH] [oil-language] Revert the dynamic check for var/const. It messed up the loop use case. --- core/state.py | 15 ++++++--------- spec/oil-assign.test.sh | 3 ++- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/core/state.py b/core/state.py index 0a16c20c4d..c92ce90d78 100644 --- a/core/state.py +++ b/core/state.py @@ -1276,15 +1276,12 @@ def _CheckOilKeyword(self, keyword_id, name, cell): definition and mutation will help translate the Oil subset of OSH to static languages. """ - if cell is not None and keyword_id in (Id.KW_Var, Id.KW_Const): - # This dynamic check is for 'local' before 'var', or 'readonly before - # 'const', etc. - # - # Another option: REMOVE assignment builtins from 'proc'. You can only - # use keywords. - - # TODO: location - e_die('%r has already been declared', name) + # This dynamic check can prevent 'local' before 'var', or 'readonly before + # 'const', etc. But it also prevents 'var' in a loop, which we don't want. + # TODO: Possibly disable local/readonly/declare inside 'proc'. + + # if cell is not None and keyword_id in (Id.KW_Var, Id.KW_Const): + # e_die('%r has already been declared', name) # TODO: Also do this at parse time. We have some name resolution in # ctx_Declarations. diff --git a/spec/oil-assign.test.sh b/spec/oil-assign.test.sh index 5ada30ceeb..6ac1b475c3 100644 --- a/spec/oil-assign.test.sh +++ b/spec/oil-assign.test.sh @@ -278,7 +278,8 @@ run --assign-status :st eval 'readonly-const' || true echo status=$st ## STDOUT: -status=1 +x=2 +status=0 status=1 ## END