mirror of https://github.com/astral-sh/ruff
Fix unrelated negation edge case
This commit is contained in:
parent
14aa8bb871
commit
0006df9292
|
|
@ -39,6 +39,13 @@ def both(x: int):
|
||||||
reveal_type(x // x) # revealed: int
|
reveal_type(x // x) # revealed: int
|
||||||
reveal_type(x / x) # revealed: int | float
|
reveal_type(x / x) # revealed: int | float
|
||||||
reveal_type(x % x) # revealed: int
|
reveal_type(x % x) # revealed: int
|
||||||
|
|
||||||
|
# Edge case where negation leads to overflow:
|
||||||
|
i64_max = 9223372036854775807
|
||||||
|
i64_min = -i64_max - 1
|
||||||
|
reveal_type(i64_max) # revealed: Literal[9223372036854775807]
|
||||||
|
reveal_type(i64_min) # revealed: Literal[-9223372036854775808]
|
||||||
|
reveal_type(-i64_min) # revealed: int
|
||||||
```
|
```
|
||||||
|
|
||||||
## Power
|
## Power
|
||||||
|
|
|
||||||
|
|
@ -6349,7 +6349,10 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> {
|
||||||
(_, Type::Never) => Type::Never,
|
(_, Type::Never) => Type::Never,
|
||||||
|
|
||||||
(ast::UnaryOp::UAdd, Type::IntLiteral(value)) => Type::IntLiteral(value),
|
(ast::UnaryOp::UAdd, Type::IntLiteral(value)) => Type::IntLiteral(value),
|
||||||
(ast::UnaryOp::USub, Type::IntLiteral(value)) => Type::IntLiteral(-value),
|
(ast::UnaryOp::USub, Type::IntLiteral(value)) => value
|
||||||
|
.checked_neg()
|
||||||
|
.map(Type::IntLiteral)
|
||||||
|
.unwrap_or_else(|| KnownClass::Int.to_instance(self.db())),
|
||||||
(ast::UnaryOp::Invert, Type::IntLiteral(value)) => Type::IntLiteral(!value),
|
(ast::UnaryOp::Invert, Type::IntLiteral(value)) => Type::IntLiteral(!value),
|
||||||
|
|
||||||
(ast::UnaryOp::UAdd, Type::BooleanLiteral(bool)) => Type::IntLiteral(i64::from(bool)),
|
(ast::UnaryOp::UAdd, Type::BooleanLiteral(bool)) => Type::IntLiteral(i64::from(bool)),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue