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 incompatible dictionary unpack #4959

Closed
JukkaL opened this issue Apr 24, 2018 · 0 comments · Fixed by #4966
Closed

Crash on incompatible dictionary unpack #4959

JukkaL opened this issue Apr 24, 2018 · 0 comments · Fixed by #4966
Assignees
Labels

Comments

@JukkaL
Copy link
Collaborator

JukkaL commented Apr 24, 2018

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
@JukkaL JukkaL added the crash label Apr 24, 2018
@JukkaL JukkaL self-assigned this Apr 24, 2018
JukkaL added a commit that referenced this issue Apr 25, 2018
Also fix crash on incompatible dictionary unpack. Fixes #4959.

Work towards #4951.
JukkaL added a commit that referenced this issue Apr 26, 2018
…4966)

Also fix crash on incompatible dictionary unpack. Fixes #4959.

Work towards #4951.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant