Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix an analyzer crash with multiple list comprehensions in py3 #447

Merged
merged 1 commit into from
Jul 31, 2017

Conversation

stealthycoin
Copy link
Contributor

The crash was caused by selecting the wrong child symbol table for the
list comprehension. Previously we were always selecting the first one in
the list of subtables. This is wrong if there is more than 1 list
comprehension, since each one gets its own subtable. This is works fine
if the list comprehension only uses symbols defined within itself or
symbols that are shared between it and the first list comprehension in
the enclosing scope, since that will resolve to the same value. The
specific error case we are fixing is when there is a list comprehension
that is not the first one that references a symbol from the enclosing
function scope that the first list comprehension does not reference.

Both the symbol tables and the ListComp node are annotated with a line
number attribute, by matching these up we can select the correct
subtable to go with our list comprehension. This is still naive, but is
better than what we had before.

fixes #412

cc @jamesls

The crash was caused by selecting the wrong child symbol table for the
list comprehension. Previously we were always selecting the first one in
the list of subtables. This is wrong if there is more than 1 list
comprehension, since each one gets its own subtable. This is works fine
if the list comprehension only uses symbols defined within itself or
symbols that are shared between it and the first list comprehension in
the enclosing scope, since that will resolve to the same value. The
specific error case we are fixing is when there is a list comprehension
that is not the first one that references a symbol from the enclosing
function scope that the first list comprehension does not reference.

Both the symbol tables and the ListComp node are annotated with a line
number attribute, by matching these up we can select the correct
subtable to go with our list comprehension. This is still naive, but is
better than what we had before.

fixes aws#412
@stealthycoin stealthycoin requested a review from jamesls July 31, 2017 17:08
@codecov-io
Copy link

Codecov Report

Merging #447 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff           @@
##           master    #447   +/-   ##
======================================
  Coverage    93.6%   93.6%           
======================================
  Files          18      18           
  Lines        2863    2863           
  Branches      375     375           
======================================
  Hits         2680    2680           
  Misses        132     132           
  Partials       51      51
Impacted Files Coverage Δ
chalice/analyzer.py 91.12% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 69f18d7...bdee4eb. Read the comment docs.

@stealthycoin stealthycoin merged commit 42aae05 into aws:master Jul 31, 2017
@stealthycoin stealthycoin deleted the fix-analyzer-crash branch July 31, 2017 17:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fail to analyze list comprehension code
4 participants