Permalink
Browse files
Fix error messages when there is a redirect with an assignment.
- Loading branch information...
Showing
with
13 additions
and
4 deletions.
-
+8
−4
osh/cmd_parse.py
-
+5
−0
osh/cmd_parse_test.py
|
|
@@ -590,9 +590,11 @@ def ParseSimpleCommand(self): |
|
|
prefix_bindings, suffix_words = self._SplitSimpleCommandPrefix(words)
|
|
|
|
|
|
if not suffix_words: # ONE=1 TWO=2 (with no other words)
|
|
|
# TODO: Have a strict mode to prevent this?
|
|
|
if redirects: # >out.txt g=foo
|
|
|
util.warn('WARNING: Got redirects in assignment: %s', redirects)
|
|
|
if redirects:
|
|
|
# TODO: redirect ops should have a token with location info instead of
|
|
|
# an op_id.
|
|
|
self.AddErrorContext('Got redirects in global assignment')
|
|
|
return None
|
|
|
|
|
|
pairs = []
|
|
|
for lhs, op, rhs, spid in prefix_bindings:
|
|
|
@@ -611,7 +613,9 @@ def ParseSimpleCommand(self): |
|
|
kind, kw_token = word.KeywordToken(suffix_words[0])
|
|
|
if kind == Kind.Assign:
|
|
|
if redirects:
|
|
|
self.AddErrorContext('Got redirects in assignment: %s', redirects)
|
|
|
# Attach the error location to the keyword. It would be more precise
|
|
|
# to attach it to the
|
|
|
self.AddErrorContext('Got redirects in assignment', token=kw_token)
|
|
|
return None
|
|
|
|
|
|
if prefix_bindings: # FOO=bar local spam=eggs not allowed
|
|
|
|
|
|
@@ -1253,6 +1253,11 @@ def testArraySyntax(self): |
|
|
"""Enumerating errors in arith_parse.py."""
|
|
|
err = _assertParseCommandListError(self, 'A= (1 2)')
|
|
|
|
|
|
def testRedirectsInAssignment(self):
|
|
|
"""Enumerating errors in arith_parse.py."""
|
|
|
err = _assertParseCommandListError(self, 'x=1 >/dev/null')
|
|
|
err = _assertParseCommandListError(self, 'declare x=1 >/dev/null')
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
unittest.main()
|
0 comments on commit
3ed19ba