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

Crash on compilation of invalid AST involving walrus #109351

Closed
JelleZijlstra opened this issue Sep 12, 2023 · 0 comments
Closed

Crash on compilation of invalid AST involving walrus #109351

JelleZijlstra opened this issue Sep 12, 2023 · 0 comments
Labels
type-crash A hard crash of the interpreter, possibly with a core dump

Comments

@JelleZijlstra
Copy link
Member

JelleZijlstra commented Sep 12, 2023

Running this file:

import ast
m = ast.Module(
    body=[
        ast.Expr(
            value=ast.ListComp(
                elt=ast.NamedExpr(
                    target=ast.Constant(value=1),
                    value=ast.Constant(value=3),
                ),
                generators=[
                    ast.comprehension(
                        target=ast.Name(id="x", ctx=ast.Store()),
                        iter=ast.Name(id="y", ctx=ast.Load()),
                        ifs=[],
                        is_async=0,
                    )
                ],
            )
        )
    ],
    type_ignores=[],
)

compile(ast.fix_missing_locations(m), "<file>", "exec")

Causes:

% ./python.exe namedexpr.py 
Assertion failed: (e->kind == Name_kind), function symtable_extend_namedexpr_scope, file symtable.c, line 1877.
zsh: abort      ./python.exe namedexpr.py

This is on a debug build; on a release build presumably it will segfault or trigger UB somewhere.

I'll have a fix soon.

On 3.11 the reproducer instead fails with TypeError: '<' not supported between instances of 'int' and 'str' for me. Not sure what's up with that; the code that should trigger the crash is the same on 3.11 and main.

Linked PRs

JelleZijlstra added a commit to JelleZijlstra/cpython that referenced this issue Sep 12, 2023
@AlexWaygood AlexWaygood added the type-crash A hard crash of the interpreter, possibly with a core dump label Sep 13, 2023
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Sep 13, 2023
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Sep 13, 2023
JelleZijlstra added a commit that referenced this issue Sep 13, 2023
…GH-109352) (#109380)

gh-109351: Fix crash when compiling AST with invalid NamedExpr (GH-109352)
(cherry picked from commit 79101ed)

Co-authored-by: Jelle Zijlstra <[email protected]>
Yhg1s pushed a commit that referenced this issue Oct 2, 2023
…GH-109352) (#109379)

gh-109351: Fix crash when compiling AST with invalid NamedExpr (GH-109352)
(cherry picked from commit 79101ed)

Co-authored-by: Jelle Zijlstra <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-crash A hard crash of the interpreter, possibly with a core dump
Projects
None yet
Development

No branches or pull requests

2 participants