Skip to content

Pyrefly doesn't reveal type as Never in unreachable code #3202

@MarcoGorelli

Description

@MarcoGorelli

Describe the Bug

from typing import Literal, assert_never, reveal_type

def main(some: Literal['a']) -> None:
    if some != 'a':
        assigned = 'b'
        reveal_type(assigned)
        assert_never(assigned)
INFO revealed type: Literal['b'] [reveal-type]
 --> t.py:6:20
  |
6 |         reveal_type(assigned)
  |                    ----------
  |
ERROR Argument `Literal['b']` is not assignable to parameter `arg` with type `Never` in function `typing.assert_never` [bad-argument-type]
 --> t.py:7:22
  |
7 |         assert_never(assigned)
  |                      ^^^^^^^^
  |
 INFO 1 error

mypy and pyright just don't report on this path at all

ty gives

info[revealed-type]: Revealed type
 --> t.py:6:21
  |
6 |         reveal_type(assigned)
  |                     ^^^^^^^^ `Never`
  |

Found 1 diagnostic

Sandbox Link

https://pyrefly.org/sandbox/?project=N4IgZglgNgpgziAXKOBDAdgEwEYHsAeAdAA4CeS4ATrgLYAEALqcROgOZ0Q3G6UN0AZCAxiVUUADR1UcOKIYB9dDABuoqZVUxxCpsRgAddEcwwwdGqlYAKOLRiJBw0eIDaAclTuAugEo6ALQAfHQAcrjKiEZ0MZzmdjQwdACEALx0nu5R6LG50rIQbMqYdOnu2O7ReTGaajp6MNYycIXFvlXVzfJKWpRNBUUwmL4gEiBkmmBQpIQMtFAUAMR0AAqkk9N0aFh4%2BHQAxhGQbACuYgwQEYRGywDKMEkAFgwMxHCIAPQfE2bThLxsD4wdAfTC4fZwD6HdDHM6oC4RD50MC8aQqKxQVDYWAHI6FOEInK4YiEuDXdBkBiPCIBNSUFoRUp0AwgADMhAAjAAmFlGVyiaj07xGE7oLg8PhDAKYCCafYXNRM9ytXgwSrodC4BgBTQARxOsqlAGsYKQAqh9vt4HAlQB3VCUdDqkAAXzGFoVMAAYtAYBRtjgCCRyC6gA

(Only applicable for extension issues) IDE Information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions