Skip to content

IndexError crash in len_callback when checking len() #20755

@correctmost

Description

@correctmost

Crash Report

I see the following IndexError crash with mypy master (b71d355), but not 1.19.1. The crash bisects to 8a1ebf3.

Traceback

Traceback (most recent call last):
  File ".venv-mypy/bin/mypy", line 6, in <module>
    sys.exit(console_entry())
  File "mypy/mypy/__main__.py", line 15, in console_entry
    main()
  File "mypy/mypy/main.py", line 135, in main
    res, messages, blockers = run_build(sources, options, fscache, t0, stdout, stderr)
  File "mypy/mypy/main.py", line 219, in run_build
    res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
  File "mypy/mypy/build.py", line 371, in build
    result = build_inner(
  File "mypy/mypy/build.py", line 468, in build_inner
    graph = dispatch(sources, manager, stdout)
  File "mypy/mypy/build.py", line 3454, in dispatch
    process_graph(graph, manager)
  File "mypy/mypy/build.py", line 3875, in process_graph
    done, still_working, results = manager.wait_for_done(graph)
  File "mypy/mypy/build.py", line 1179, in wait_for_done
    process_stale_scc(graph, next_scc, self)
  File "mypy/mypy/build.py", line 4039, in process_stale_scc
    graph[id].type_check_first_pass()
  File "mypy/mypy/build.py", line 2819, in type_check_first_pass
    self.type_checker().check_first_pass()
  File "mypy/mypy/checker.py", line 537, in check_first_pass
    self.accept(d)
  File "mypy/mypy/checker.py", line 648, in accept
    stmt.accept(self)
  File "mypy/mypy/nodes.py", line 1602, in accept
    return visitor.visit_expression_stmt(self)
  File "mypy/mypy/checker.py", line 4925, in visit_expression_stmt
    expr_type = self.expr_checker.accept(s.expr, allow_none_return=True, always_allow_any=True)
  File "mypy/mypy/checkexpr.py", line 6036, in accept
    typ = self.visit_call_expr(node, allow_none_return=True)
  File "mypy/mypy/checkexpr.py", line 508, in visit_call_expr
    return self.visit_call_expr_inner(e, allow_none_return=allow_none_return)
           ~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "mypy/mypy/checkexpr.py", line 645, in visit_call_expr_inner
    ret_type = self.check_call_expr_with_callee_type(
        callee_type, e, fullname, object_type, member
    )
  File "mypy/mypy/checkexpr.py", line 1495, in check_call_expr_with_callee_type
    ret_type, callee_type = self.check_call(
                            ~~~~~~~~~~~~~~~^
        callee_type,
        ^^^^^^^^^^^^
    ...<6 lines>...
        object_type=object_type,
        ^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "mypy/mypy/checkexpr.py", line 1588, in check_call
    return self.check_callable_call(
           ~~~~~~~~~~~~~~~~~~~~~~~~^
        callee,
        ^^^^^^^
    ...<6 lines>...
        object_type,
        ^^^^^^^^^^^^
    )
    ^
  File "mypy/mypy/checkexpr.py", line 1831, in check_callable_call
    new_ret_type = self.apply_function_plugin(
        callee,
    ...<7 lines>...
        context,
    )
  File "mypy/mypy/checkexpr.py", line 1269, in apply_function_plugin
    return callback(
        FunctionContext(
    ...<8 lines>...
        )
    )
  File "mypy/mypy/plugins/default.py", line 221, in len_callback
    arg_type = ctx.arg_types[0][0]
               ~~~~~~~~~~~~~~~~^^^
IndexError: list index out of range

To Reproduce

len()

Your Environment

  • Mypy version used: b71d355
  • Mypy command-line flags: N/A
  • Mypy configuration options from mypy.ini (and other config files): N/A
  • Python version used: 3.14.2
  • Operating system and version: Arch Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions