Skip to content

Commit

Permalink
[errors] Fix crash in LeftMostSpanForWord.
Browse files Browse the repository at this point in the history
All spec tests pass.
  • Loading branch information
Andy Chu committed Sep 2, 2019
1 parent f80b30a commit 372a5d1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
1 change: 0 additions & 1 deletion osh/braces.py
Expand Up @@ -220,7 +220,6 @@ def _BraceDetect(w):
# ? We're forcing braces right now but not commas.
if stack:
stack[-1].saw_comma = True

stack[-1].alt_part.words.append(word.Compound(cur_parts))
cur_parts = [] # clear
append = False
Expand Down
15 changes: 7 additions & 8 deletions osh/word_.py
Expand Up @@ -231,7 +231,11 @@ def _RightMostSpanForPart(part):
def LeftMostSpanForWord(w):
# type: (word_t) -> int
if isinstance(w, word__Compound):
return LeftMostSpanForPart(w.parts[0])
if w.parts:
return LeftMostSpanForPart(w.parts[0])
else:
# This is possible for empty brace sub alternative {a,b,}
return const.NO_INTEGER

elif isinstance(w, word__Token):
return w.token.span_id
Expand All @@ -240,13 +244,8 @@ def LeftMostSpanForWord(w):
return const.NO_INTEGER

elif isinstance(w, word__BracedTree):
if len(w.parts) == 0: # Is this possible?
return const.NO_INTEGER
else:
begin = w.parts[0]
# TODO: We need to combine LineSpan()? If they're both on the same line,
# return them both. If they're not, then just use "begin"?
return LeftMostSpanForPart(begin)
# This should always have one part?
return LeftMostSpanForPart(w.parts[0])

elif isinstance(w, word__String):
return w.spids[0] # See _StringWordEmitter in osh/builtin_bracket.py
Expand Down

0 comments on commit 372a5d1

Please sign in to comment.