Skip to content

Stack overflow in solver on a specific recursion pattern in protocols #1905

@stroxler

Description

@stroxler

Describe the Bug

Repro:

from typing import Generic, TypeVar, Protocol, Callable

T = TypeVar('T')
U = TypeVar('U')

class Functor(Protocol[T]):
    """A Functor protocol - common in functional programming."""
    def map(self, f: Callable[[T], U]) -> Functor[U]: ...

class Maybe(Generic[T]):
    """A Maybe/Option type that should implement Functor."""
    value: T | None
    def map(self, f: Callable[[T], U]) -> Maybe[U]: ...

def test():
    m: Maybe[int] = ...  # type: ignore
    f: Functor[int] = m  # Stack overflow here!

Sandbox Link

No response

(Only applicable for extension issues) IDE Information

No response

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions