Skip to content

Crash on incompatible dictionary unpack #4959

Closed

Description

@JukkaL

Type checking this code fragment causes a mypy crash:

from typing import Dict

def f() -> Dict[int, str]:
    return {1: '', **d()}

def d() -> Dict[int, int]:
    return {}

Here's the traceback:

Traceback (most recent call last):
  File "/Users/jukka/src/mypy/scripts/mypy", line 6, in <module>
    main(__file__)
  File "/Users/jukka/src/mypy/mypy/main.py", line 88, in main
    res = type_check_only(sources, bin_dir, options, flush_errors)  # noqa
  File "/Users/jukka/src/mypy/mypy/main.py", line 143, in type_check_only
    flush_errors=flush_errors)
  File "/Users/jukka/src/mypy/mypy/build.py", line 183, in build
    flush_errors, fscache)
  File "/Users/jukka/src/mypy/mypy/build.py", line 268, in _build
    graph = dispatch(sources, manager)
  File "/Users/jukka/src/mypy/mypy/build.py", line 2253, in dispatch
    process_graph(graph, manager)
  File "/Users/jukka/src/mypy/mypy/build.py", line 2543, in process_graph
    process_stale_scc(graph, scc, manager)
  File "/Users/jukka/src/mypy/mypy/build.py", line 2659, in process_stale_scc
    graph[id].type_check_first_pass()
  File "/Users/jukka/src/mypy/mypy/build.py", line 1903, in type_check_first_pass
    self.type_checker().check_first_pass()
  File "/Users/jukka/src/mypy/mypy/checker.py", line 252, in check_first_pass
    self.accept(d)
  File "/Users/jukka/src/mypy/mypy/checker.py", line 351, in accept
    stmt.accept(self)
  File "/Users/jukka/src/mypy/mypy/nodes.py", line 539, in accept
    return visitor.visit_func_def(self)
  File "/Users/jukka/src/mypy/mypy/checker.py", line 607, in visit_func_def
    self._visit_func_def(defn)
  File "/Users/jukka/src/mypy/mypy/checker.py", line 611, in _visit_func_def
    self.check_func_item(defn, name=defn.name())
  File "/Users/jukka/src/mypy/mypy/checker.py", line 671, in check_func_item
    self.check_func_def(defn, typ, name)
  File "/Users/jukka/src/mypy/mypy/checker.py", line 834, in check_func_def
    self.accept(item.body)
  File "/Users/jukka/src/mypy/mypy/checker.py", line 351, in accept
    stmt.accept(self)
  File "/Users/jukka/src/mypy/mypy/nodes.py", line 804, in accept
    return visitor.visit_block(self)
  File "/Users/jukka/src/mypy/mypy/checker.py", line 1433, in visit_block
    self.accept(s)
  File "/Users/jukka/src/mypy/mypy/checker.py", line 351, in accept
    stmt.accept(self)
  File "/Users/jukka/src/mypy/mypy/nodes.py", line 919, in accept
    return visitor.visit_return_stmt(self)
  File "/Users/jukka/src/mypy/mypy/checker.py", line 2204, in visit_return_stmt
    self.check_return_stmt(s)
  File "/Users/jukka/src/mypy/mypy/checker.py", line 2235, in check_return_stmt
    allow_none_return=allow_none_func_call)
  File "/Users/jukka/src/mypy/mypy/checkexpr.py", line 2379, in accept
    typ = node.accept(self)
  File "/Users/jukka/src/mypy/mypy/nodes.py", line 1570, in accept
    return visitor.visit_dict_expr(self)
  File "/Users/jukka/src/mypy/mypy/checkexpr.py", line 2018, in visit_dict_expr
    self.check_call(method, [arg], [nodes.ARG_POS], arg)
  File "/Users/jukka/src/mypy/mypy/checkexpr.py", line 620, in check_call
    object_type=object_type)
  File "/Users/jukka/src/mypy/mypy/checkexpr.py", line 587, in check_call
    messages=arg_messages)
  File "/Users/jukka/src/mypy/mypy/checkexpr.py", line 1061, in check_argument_types
    actual + 1, i + 1, callee, context, messages)
  File "/Users/jukka/src/mypy/mypy/checkexpr.py", line 1097, in check_arg
    caller_kind, context)
  File "/Users/jukka/src/mypy/mypy/messages.py", line 643, in incompatible_argument
    arg_name = context.arg_names[n - 1]
IndexError: list index out of range

Activity

  1. self-assigned this
    on Apr 24, 2018
  2. added a commit that references this issue on Apr 25, 2018
    85310a4
  3. added a commit that references this issue on Apr 26, 2018
    7b257c8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions