wilcoxjay/mypyvy

Look for other places where we potentially have nonexhaustive case analysis

Opened this issue · 0 comments

I'd like to have a more systematic approach to discovering bugs such as #25. Here's a prototype

class Nothing:
    pass

def unreachable(x: Nothing) -> None:
    pass

and then in the case analysis

e: Expr
if isinstance(e, syntax.Id):
    ...
... # other cases
else:
    unreachable(e)  # this line will report a compile-time type error unless the else branch is unreachable
    assert False  # this line will report a run-time error if reached

Edit: Starting in Python 3.11, mypy will have direct support for assert_never that does exactly what we want. But in older versions, apparently you can use NoReturn as a bottom type.