This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: pegen parser: Multiline eval with assignment to function call: assertion failed
Type: crash Stage: resolved
Components: Interpreter Core Versions: Python 3.10, Python 3.9
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: gvanrossum, lys.nikolaou, mdk, pablogsal, terry.reedy, vstinner
Priority: normal Keywords: 3.9regression, patch

Created on 2021-01-04 20:48 by mdk, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 24107 closed pablogsal, 2021-01-05 01:32
PR 24124 closed lys.nikolaou, 2021-01-05 20:24
PR 24140 merged lys.nikolaou, 2021-01-06 12:53
Messages (8)
msg384348 - (view) Author: Julien Palard (mdk) * (Python committer) Date: 2021-01-04 20:48
Tested in 3.9.0 and master (127dde5916):

$ cat
    """[file for str(file) in []

$ ./python
python: Parser/pegen.c:149: byte_offset_to_character_offset: Assertion `col_offset >= 0 && (unsigned long)col_offset <= strlen(str)' failed.
Fatal Python error: Aborted

Current thread 0x00007f6454cfe280 (most recent call first):
  File "/home/mdk/clones/python/cpython/", line 1 in <module>
Aborted (core dumped)

(Adding Guido and Pablo to nosy as, IIRC, you're interested in parser things :))
msg384349 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-01-04 20:53
Reproducer as a single line:

compile("[file for str(file) in []\n]", "string", "exec")
msg384350 - (view) Author: Julien Palard (mdk) * (Python committer) Date: 2021-01-04 21:19
According to git bisect it come from 01ece63d42b830df106948db0aefa6c1ba24416a, thanks Victor for adding Lysandros, you had a good feeling :)
msg384360 - (view) Author: Lysandros Nikolaou (lys.nikolaou) * (Python committer) Date: 2021-01-04 23:42
Thanks for letting us know, Julien! I've identified the bug and where it comes from and I'll probably work on it tomorrow.
msg385085 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2021-01-14 21:36
New changeset e5fe509054183bed9aef42c92da8407d339e8af8 by Lysandros Nikolaou in branch 'master':
bpo-42827: Fix crash on SyntaxError in multiline expressions (GH-24140)
msg385087 - (view) Author: Lysandros Nikolaou (lys.nikolaou) * (Python committer) Date: 2021-01-14 22:34
This is now fixed.
msg385092 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2021-01-15 01:26
On Windows, Victor's one liner failed on repository debug builds with Windows' process error popup.  I have seen this mysterious failure at least once when testing IDLE Shell running on the repository build.   After the patch, my debug build gives the correct message,
  SyntaxError: cannot assign to function call
and correctly points to the 's' of 'str' on the first line.  Ditto when run from IDLE's Shell or editor.  Thank you for the fix.

Installed Python 3.10.0a4, Jan 4, gives the correct message  but confusingly points at the final ']' on a line by itself.  The latter should be fixed in the next release.
msg385093 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2021-01-15 01:52
In order to test code.InteractiveCompiler (used by IDLE) and codeop._maybe_compile (which IC calls), which calls compile() 3 times with mode 'single', I entered the example as 2 or 3 lines in Shell.
>>> [file for str(file) in []  # Error highlight on 's'.
SyntaxError: cannot assign to function call

Breaking the expression elsewhere, including before 'str', gives the same message and highlighted 's'.

I did not test before recompiling but it is certainly correct now.
Date User Action Args
2022-04-11 14:59:39adminsetgithub: 86993
2021-01-15 01:52:49terry.reedysetmessages: + msg385093
2021-01-15 01:26:32terry.reedysetnosy: + terry.reedy
messages: + msg385092
2021-01-14 22:34:41lys.nikolaousetstatus: open -> closed
resolution: fixed
messages: + msg385087

stage: patch review -> resolved
2021-01-14 21:36:39pablogsalsetmessages: + msg385085
2021-01-06 12:53:38lys.nikolaousetpull_requests: + pull_request22969
2021-01-05 20:24:01lys.nikolaousetpull_requests: + pull_request22954
2021-01-05 01:32:55pablogsalsetkeywords: + patch
stage: patch review
pull_requests: + pull_request22936
2021-01-04 23:42:31lys.nikolaousetmessages: + msg384360
2021-01-04 21:19:46mdksetmessages: + msg384350
2021-01-04 20:54:00vstinnersettitle: Multiline eval with assignment to function call segfaults -> pegen parser: Multiline eval with assignment to function call: assertion failed
2021-01-04 20:53:07vstinnersetversions: + Python 3.9
nosy: + vstinner, lys.nikolaou

messages: + msg384349

components: + Interpreter Core
keywords: + 3.9regression
2021-01-04 20:48:09mdkcreate