Skip to content

Commit 9d59c3b

Browse files
committed
Update UnaryMinusHandler.php
1 parent ed9dfbd commit 9d59c3b

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/Analyser/Generator/ExprHandler/UnaryMinusHandler.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
use PHPStan\DependencyInjection\AutowiredService;
1717
use PHPStan\Reflection\InitializerExprTypeResolver;
1818
use PHPStan\Type\IntegerRangeType;
19-
use function PHPStan\dumpType;
2019

2120
/**
2221
* @implements ExprHandler<Expr\UnaryMinus>
@@ -42,7 +41,7 @@ public function analyseExpr(Stmt $stmt, Expr $expr, GeneratorScope $scope, Expre
4241
$nativeType = $this->initializerExprTypeResolver->getUnaryMinusTypeFromType($expr->expr, $result->nativeType);
4342
if ($type instanceof IntegerRangeType) {
4443
$mulResult = yield new ExprAnalysisRequest($stmt, new Expr\BinaryOp\Mul($expr, new Int_(-1)), $scope, $context->enterDeep(), new NoopNodeCallback());
45-
$type = $mulResult->result;
44+
$type = $mulResult->type;
4645
$nativeType = $mulResult->nativeType;
4746
}
4847

tests/PHPStan/Analyser/Generator/data/gnsr.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,14 +191,19 @@ public function doConcat($a, $b, string $c, string $d): void
191191
assertNativeType('string', $c . $d);
192192
}
193193

194-
function doUnaryPlus(int $i)
194+
/**
195+
* @param int $ii
196+
*/
197+
function doUnaryPlus(int $i, $ii)
195198
{
196199
$a = '1';
197200

198201
assertType('1', +$a);
199202
assertNativeType('1', +$a);
200203
assertType('int', +$i);
201204
assertNativeType('int', +$i);
205+
assertType('int', +$ii);
206+
assertNativeType('float|int', +$ii);
202207
}
203208

204209
function doUnaryMinus(int $i) {

0 commit comments

Comments
 (0)