Skip to content

Daemon crash when removing type parameter #7197

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

Closed
msullivan opened this issue Jul 11, 2019 · 3 comments
Closed

Daemon crash when removing type parameter #7197

msullivan opened this issue Jul 11, 2019 · 3 comments

Comments

@msullivan
Copy link
Collaborator

In certain circumstances the daemon will crash with an array out of bounds error when a type parameter is removed from a class:

[case testRemoveGeneric]
[file a.py]
from typing import Generic, TypeVar
T = TypeVar('T')
class A(Generic[T]): pass

[file a.py.2]
from typing import Generic, TypeVar
T = TypeVar('T')
class A: pass

[file b.py]
from a import A
from d import take

def foo() -> None:
    take([A()])

[file d.py]
from typing import List
from a import A
def take(x: List[A]): pass

[builtins fixtures/list.pyi]
[out]
==

crashes with a traceback ending in

  File "/home/msullivan/src/mypy/mypy/checkexpr.py", line 812, in check_callable_call
    callee, args, arg_kinds, formal_to_actual, context)
  File "/home/msullivan/src/mypy/mypy/checkexpr.py", line 1027, in infer_function_type_arguments
    strict=self.chk.in_checked_function())
  File "/home/msullivan/src/mypy/mypy/infer.py", line 31, in infer_function_type_arguments
    callee_type, arg_types, arg_kinds, formal_to_actual)
  File "/home/msullivan/src/mypy/mypy/constraints.py", line 63, in infer_constraints_for_callable
    c = infer_constraints(callee.arg_types[i], actual_type, SUPERTYPE_OF)
  File "/home/msullivan/src/mypy/mypy/constraints.py", line 140, in infer_constraints
    return template.accept(ConstraintBuilderVisitor(actual, direction))
  File "/home/msullivan/src/mypy/mypy/types.py", line 667, in accept
    return visitor.visit_instance(self)
  File "/home/msullivan/src/mypy/mypy/constraints.py", line 325, in visit_instance
    if tvars[j].variance != CONTRAVARIANT:
@ilevkivskyi
Copy link
Member

Isn't it just a duplicate of #3279 but "reversed" (in the existing issue, the out of bound errors appear when a non-generic class is turned into generic)?

@ilevkivskyi
Copy link
Member

Actually the original issue has a recipe for this "direction" too, see #3279 (comment) (although the crash actually happens in a different visitor I believe the cause is the same).

@msullivan
Copy link
Collaborator Author

Yeah I think so

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

No branches or pull requests

2 participants