Skip to content

New semantic analyzer: crash when function has multiple definitions #6432

Closed

Description

@JukkaL

Conditionally redefining a function as an overloaded function results in a crash. Example:

from typing import overload

if int():
    def f(x: int) -> None:
        pass
else:
    @overload
    def f(x: int) -> None: ...
    @overload
    def f(x: str) -> None: ...
    def f(x) -> None:
        yadsf

Traceback:

  File "/Users/jukka/src/mypy/mypy/build.py", line 162, in build
    result = _build(sources, options, alt_lib_path, flush_errors, fscache)
  File "/Users/jukka/src/mypy/mypy/build.py", line 217, in _build
    graph = dispatch(sources, manager)
  File "/Users/jukka/src/mypy/mypy/build.py", line 2433, in dispatch
    process_graph(graph, manager)
  File "/Users/jukka/src/mypy/mypy/build.py", line 2738, in process_graph
    process_stale_scc(graph, scc, manager)
  File "/Users/jukka/src/mypy/mypy/build.py", line 2836, in process_stale_scc
    semantic_analysis_for_scc(graph, scc, manager.errors)
  File "/Users/jukka/src/mypy/mypy/newsemanal/semanal_main.py", line 62, in semantic_analysis_for_scc
    check_type_arguments(graph, scc, errors)
  File "/Users/jukka/src/mypy/mypy/newsemanal/semanal_main.py", line 214, in check_type_arguments
    state.tree.accept(analyzer)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/contextlib.py", line 99, in __exit__
    self.gen.throw(type, value, traceback)
  File "/Users/jukka/src/mypy/mypy/build.py", line 1754, in wrap_context
    yield
  File "/Users/jukka/src/mypy/mypy/newsemanal/semanal_main.py", line 214, in check_type_arguments
    state.tree.accept(analyzer)
  File "/Users/jukka/src/mypy/mypy/nodes.py", line 249, in accept
    return visitor.visit_mypy_file(self)
  File "/Users/jukka/src/mypy/mypy/newsemanal/semanal_typeargs.py", line 28, in visit_mypy_file
    super().visit_mypy_file(o)
  File "/Users/jukka/src/mypy/mypy/traverser.py", line 33, in visit_mypy_file
    d.accept(self)
  File "/Users/jukka/src/mypy/mypy/nodes.py", line 1102, in accept
    return visitor.visit_if_stmt(self)
  File "/Users/jukka/src/mypy/mypy/traverser.py", line 120, in visit_if_stmt
    o.else_body.accept(self)
  File "/Users/jukka/src/mypy/mypy/nodes.py", line 911, in accept
    return visitor.visit_block(self)
  File "/Users/jukka/src/mypy/mypy/newsemanal/semanal_typeargs.py", line 41, in visit_block
    super().visit_block(o)
  File "/Users/jukka/src/mypy/mypy/traverser.py", line 37, in visit_block
    s.accept(self)
  File "/Users/jukka/src/mypy/mypy/nodes.py", line 454, in accept
    return visitor.visit_overloaded_func_def(self)
  File "/Users/jukka/src/mypy/mypy/traverser.py", line 56, in visit_overloaded_func_def
    item.accept(self)
  File "/Users/jukka/src/mypy/mypy/nodes.py", line 689, in accept
    return visitor.visit_decorator(self)
  File "/Users/jukka/src/mypy/mypy/traverser.py", line 70, in visit_decorator
    o.func.accept(self)
  File "/Users/jukka/src/mypy/mypy/nodes.py", line 606, in accept
    return visitor.visit_func_def(self)
  File "/Users/jukka/src/mypy/mypy/traverser.py", line 52, in visit_func_def
    self.visit_func(o)
  File "/Users/jukka/src/mypy/mypy/newsemanal/semanal_typeargs.py", line 33, in visit_func
    super().visit_func(defn)
  File "/Users/jukka/src/mypy/mypy/mixedtraverser.py", line 23, in visit_func
    self.visit_optional_type(o.type)
  File "/Users/jukka/src/mypy/mypy/mixedtraverser.py", line 90, in visit_optional_type
    t.accept(self)
  File "/Users/jukka/src/mypy/mypy/types.py", line 929, in accept
    return visitor.visit_callable_type(self)
  File "/Users/jukka/src/mypy/mypy/typetraverser.py", line 52, in visit_callable_type
    t.fallback.accept(self)
  File "/Users/jukka/src/mypy/mypy/types.py", line 620, in accept
    return visitor.visit_instance(self)
  File "/Users/jukka/src/mypy/mypy/newsemanal/semanal_typeargs.py", line 47, in visit_instance
    for (i, arg), tvar in zip(enumerate(t.args), info.defn.type_vars):
  File "/Users/jukka/src/mypy/mypy/nodes.py", line 2525, in __getattribute__
    raise AssertionError(object.__getattribute__(self, 'msg'))
AssertionError: fallback can't be filled out until semanal

Activity

  1. JukkaL commented on Feb 19, 2019

    @JukkaL
    CollaboratorAuthor

    Follow-up to #6429.

  2. JukkaL commented on Apr 5, 2019

    @JukkaL
    CollaboratorAuthor

    More generally, multiple definitions for a function can cause crashes, since some of the definitions are not reachable from the symbol table and thus won't be analyzed.

  3. changed the title [-]New semantic analyzer: redefine function as overloaded function[/-] [+]New semantic analyzer: crash when function has multiple definitions[/+] on Apr 5, 2019
  4. ilevkivskyi commented on Apr 9, 2019

    @ilevkivskyi
    Member

    It looks like this blocks #6644

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions