Skip to content

Segfault when manipulating a recursive union #15192

Closed

Description

@jonathan-laurent

Bug Report

Running mypy on the following program produces a segfault.

To Reproduce

from typing import Literal, TypeAlias, Union


Expr: TypeAlias = Union[
    tuple[Literal["const"], int],
    tuple[Literal["neg"], "Expr"],
]


def eval(e: Expr) -> int:
    if e[0] == "const":
        return e[1]
    elif e[0] == "neg":
        return -eval(e[1])

Expected Behavior

Mypy returns successfully.

Actual Behavior

Mypy segfaults:

fish: Job 1, 'mypy ...' terminated by signal SIGSEGV (Address boundary error)

The problem can be replicated in the mypy playground.

Your Environment

  • Mypy version used: 1.2.0
  • Mypy command-line flags: none
  • Mypy configuration options from mypy.ini (and other config files): none
  • Python version used: 3.11

Activity

  1. hauntsaninja commented on May 5, 2023

    @hauntsaninja
    Collaborator

    Thanks for the report! I think #15128 will fix this

  2. added a commit that references this issue on May 6, 2023
    7832e1f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongcrash

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions