[ty] Fix panic when pulling types for `UnaryOp` expressions inside `Literal` slices (#18536)

This commit is contained in:
Alex Waygood 2025-06-07 16:26:10 +01:00 committed by GitHub
parent 95497ffaab
commit 72552f31e4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 4 additions and 11 deletions

View File

@ -3,4 +3,4 @@ from typing import Literal
class Format:
STRING = "string"
def evaluate(format: Literal[Format.STRING]) -> str: ...
def evaluate(a: Literal[Format.STRING], b: Literal[-1]) -> str: ...

View File

@ -304,17 +304,8 @@ const KNOWN_FAILURES: &[(&str, bool, bool)] = &[
// These are all "expression should belong to this TypeInference region and TypeInferenceBuilder should have inferred a type for it"
("crates/ty_vendored/vendor/typeshed/stdlib/abc.pyi", true, true),
("crates/ty_vendored/vendor/typeshed/stdlib/ast.pyi", true, true),
("crates/ty_vendored/vendor/typeshed/stdlib/builtins.pyi", true, true),
("crates/ty_vendored/vendor/typeshed/stdlib/curses/__init__.pyi", true, true),
("crates/ty_vendored/vendor/typeshed/stdlib/lzma.pyi", true, true),
("crates/ty_vendored/vendor/typeshed/stdlib/os/__init__.pyi", true, true),
("crates/ty_vendored/vendor/typeshed/stdlib/pathlib/__init__.pyi", true, true),
("crates/ty_vendored/vendor/typeshed/stdlib/pathlib/types.pyi", true, true),
("crates/ty_vendored/vendor/typeshed/stdlib/pstats.pyi", true, true),
("crates/ty_vendored/vendor/typeshed/stdlib/socket.pyi", true, true),
("crates/ty_vendored/vendor/typeshed/stdlib/sqlite3/__init__.pyi", true, true),
("crates/ty_vendored/vendor/typeshed/stdlib/tempfile.pyi", true, true),
];
/// Attempting to check one of these files causes a stack overflow

View File

@ -9481,7 +9481,9 @@ impl<'db> TypeInferenceBuilder<'db, '_> {
if matches!(u.op, ast::UnaryOp::USub | ast::UnaryOp::UAdd)
&& u.operand.is_number_literal_expr() =>
{
self.infer_unary_expression(u)
let ty = self.infer_unary_expression(u);
self.store_expression_type(parameters, ty);
ty
}
_ => {
self.infer_expression(parameters);