diff --git a/crates/ty_python_semantic/resources/mdtest/terminal_statements.md b/crates/ty_python_semantic/resources/mdtest/terminal_statements.md index be592dc284..0e37c566fe 100644 --- a/crates/ty_python_semantic/resources/mdtest/terminal_statements.md +++ b/crates/ty_python_semantic/resources/mdtest/terminal_statements.md @@ -592,9 +592,13 @@ Let's try cases where the function annotated with `NoReturn` is some sub-express from typing import NoReturn import sys +# TODO: this is currently not yet supported +# error: [invalid-return-type] def _() -> NoReturn: 3 + sys.exit(1) +# TODO: this is currently not yet supported +# error: [invalid-return-type] def _() -> NoReturn: 3 if sys.exit(1) else 4 ``` diff --git a/crates/ty_python_semantic/src/semantic_index/builder.rs b/crates/ty_python_semantic/src/semantic_index/builder.rs index a64243afe8..6fc93043eb 100644 --- a/crates/ty_python_semantic/src/semantic_index/builder.rs +++ b/crates/ty_python_semantic/src/semantic_index/builder.rs @@ -1901,11 +1901,28 @@ impl<'ast> Visitor<'ast> for SemanticIndexBuilder<'_, 'ast> { value, range: _, node_index: _, - }) if self.in_module_scope() => { - if let Some(expr) = dunder_all_extend_argument(value) { - self.add_standalone_expression(expr); + }) => { + if self.in_module_scope() { + if let Some(expr) = dunder_all_extend_argument(value) { + self.add_standalone_expression(expr); + } } + self.visit_expr(value); + + if !self.source_type.is_stub() { + if let ast::Expr::Call(ast::ExprCall { func, .. }) = value.as_ref() { + let expression = self.add_standalone_expression(func); + + let predicate = Predicate { + node: PredicateNode::ReturnsNever(expression), + is_positive: false, + }; + self.record_reachability_constraint(PredicateOrLiteral::Predicate( + predicate, + )); + } + } } _ => { walk_stmt(self, stmt); @@ -2225,18 +2242,6 @@ impl<'ast> Visitor<'ast> for SemanticIndexBuilder<'_, 'ast> { } walk_expr(self, expr); } - ast::Expr::Call(ast::ExprCall { func, .. }) if !self.source_type.is_stub() => { - let expression = self.add_standalone_expression(func); - - let predicate = Predicate { - node: PredicateNode::ReturnsNever(expression), - is_positive: false, - }; - - walk_expr(self, expr); - - self.record_reachability_constraint(PredicateOrLiteral::Predicate(predicate)); - } _ => { walk_expr(self, expr); }