Add default parameter to next() to prevent StopIteration exception when no corresponding rawToken is found for '[' token (#3301)

Co-authored-by: Ivar Bonsaksen <ivar.bonsaksen@microchip.com>
This commit is contained in:
Ivar Andreas Bonsaksen 2021-06-19 20:24:21 +02:00 committed by GitHub
parent 2c8c8a5fa6
commit dc582560cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 1 deletions

View File

@ -435,7 +435,11 @@ def getElementDef(nameToken, rawTokens = None):
def createArrayChildrenDefs(ed, token, rawTokens = None):
if token.str == '[':
if rawTokens is not None:
foundToken = next(rawToken for rawToken in rawTokens if rawToken.file == token.file and rawToken.linenr == token.linenr and rawToken.column == token.column)
foundToken = next((rawToken for rawToken in rawTokens
if rawToken.file == token.file
and rawToken.linenr == token.linenr
and rawToken.column == token.column
), None)
if foundToken and foundToken.next and foundToken.next.str == ']':
ed.markAsFlexibleArray(token)