Skip to content

Commit 88a8621

Browse files
committed
Fix BcMath\Number unary plus/minus
1 parent e97e106 commit 88a8621

File tree

3 files changed

+6
-10
lines changed

3 files changed

+6
-10
lines changed

src/Type/ObjectType.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,10 @@ public function toNumber(): Type
762762
]);
763763
}
764764

765+
if ($this->isInstanceOf('BcMath\Number')->yes()) {
766+
return $this;
767+
}
768+
765769
return new ErrorType();
766770
}
767771

tests/PHPStan/Analyser/nsrt/bcmath-number.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,8 +408,8 @@ public function bcVsNever(Number $a): void
408408

409409
public function bcUnaryOp(Number $a): void
410410
{
411-
assertType('*ERROR*', +$a);
412-
assertType('*ERROR*', -$a);
411+
assertType('BcMath\Number', +$a);
412+
assertType('BcMath\Number', -$a);
413413
assertType('*ERROR*', ~$a);
414414
}
415415

tests/PHPStan/Rules/Operators/InvalidUnaryOperationRuleTest.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -173,14 +173,6 @@ public function testUnion(): void
173173
public function testBcMathNumber(): void
174174
{
175175
$this->analyse([__DIR__ . '/data/unary-bcmath-number.php'], [
176-
[
177-
'Unary operation "+" on BcMath\Number results in an error.',
178-
9,
179-
],
180-
[
181-
'Unary operation "-" on BcMath\Number results in an error.',
182-
10,
183-
],
184176
[
185177
'Unary operation "~" on BcMath\Number results in an error.',
186178
11,

0 commit comments

Comments
 (0)