Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm committed Dec 4, 2023
1 parent 88acd23 commit 0f7240f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
30 changes: 28 additions & 2 deletions src/Analyser/MutatingScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -1426,7 +1426,28 @@ private function resolveType(string $exprString, Expr $node): Type
} elseif ($node instanceof Unset_) {
return new NullType();
} elseif ($node instanceof Expr\PostInc || $node instanceof Expr\PostDec) {
return $this->getType($node->var);
$varType = $this->getType($node->var);

$stringType = new StringType();
if ($varType->isString()->yes()) {
if ($varType->isLiteralString()->yes()) {
return new IntersectionType([$stringType, new AccessoryLiteralStringType()]);
}
if ($varType->isNumericString()->yes()) {
return new BenevolentUnionType([
new IntegerType(),
new FloatType(),
]);
}

return new BenevolentUnionType([
$stringType,
new IntegerType(),
new FloatType(),
]);
}

return $varType;
} elseif ($node instanceof Expr\PreInc || $node instanceof Expr\PreDec) {
$varType = $this->getType($node->var);
$varScalars = $varType->getConstantScalarValues();
Expand Down Expand Up @@ -1454,7 +1475,12 @@ private function resolveType(string $exprString, Expr $node): Type
new FloatType(),
]);
}
return $stringType;

return new BenevolentUnionType([
$stringType,
new IntegerType(),
new FloatType(),
]);
}

if ($node instanceof Expr\PreInc) {
Expand Down
2 changes: 1 addition & 1 deletion tests/PHPStan/Analyser/data/bug-10122.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function(float $f) {
}

/** @param numeric-string $ns */
function doNumericString(string $ns) {
function doNumericString(string $ns):void {
function() use ($ns) {
assertType('(float|int)', ++$ns);
};
Expand Down

0 comments on commit 0f7240f

Please sign in to comment.