diff --git a/crates/red_knot_python_semantic/resources/mdtest/unreachable.md b/crates/red_knot_python_semantic/resources/mdtest/unreachable.md index fce99d51ce..3f56372d97 100644 --- a/crates/red_knot_python_semantic/resources/mdtest/unreachable.md +++ b/crates/red_knot_python_semantic/resources/mdtest/unreachable.md @@ -432,6 +432,44 @@ if sys.version_info >= (3, 11): import wsgiref.types ``` +### Nested scopes + +When we have nested scopes inside the unreachable section, we should not emit diagnostics either: + +```py +if False: + x = 1 + + def f(): + # TODO + # error: [unresolved-reference] + print(x) + + class C: + def __init__(self): + # TODO + # error: [unresolved-reference] + print(x) +``` + +### Use of unreachable symbols in type annotations, or as class bases + +We should not show any diagnostics in type annotations inside unreachable sections. + +```py +def _(): + class C: ... + return + + # TODO + # error: [invalid-type-form] "Variable of type `Never` is not allowed in a type expression" + c: C = C() + + # TODO + # error: [invalid-base] "Invalid class base with type `Never` (all bases must be a class, `Any`, `Unknown` or `Todo`)" + class Sub(C): ... +``` + ### Emit diagnostics for definitely wrong code Even though the expressions in the snippet below are unreachable, we still emit diagnostics for