Skip to content

Crash on compilation of invalid AST involving walrus #109351

Closed
@JelleZijlstra

Description

@JelleZijlstra

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-crashA hard crash of the interpreter, possibly with a core dump

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions