Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Analyser/MutatingScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -3401,7 +3401,7 @@ public function unsetExpression(Expr $expr): self
[],
$this->afterExtractCall,
$this->parentScope,
);
)->invalidateExpression($expr);
} elseif ($expr instanceof Expr\ArrayDimFetch && $expr->dim !== null) {
return $this->specifyExpressionType(
$expr->var,
Expand Down Expand Up @@ -3499,7 +3499,7 @@ public function specifyExpressionType(Expr $expr, Type $type, ?Type $nativeType
$this->inFunctionCallsStack,
$this->afterExtractCall,
$this->parentScope,
);
)->invalidateExpression($expr);
} elseif ($expr instanceof Expr\ArrayDimFetch && $expr->dim !== null) {
$constantArrays = TypeUtils::getOldConstantArrays($this->getType($expr->var));
if (count($constantArrays) > 0) {
Expand Down
1 change: 1 addition & 0 deletions tests/PHPStan/Analyser/NodeScopeResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,7 @@ public function dataFileAsserts(): iterable
yield from $this->gatherAssertTypes(__DIR__ . '/data/remember-possibly-impure-function-values.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/emptyiterator.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/collected-data.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-1396.php');
}

/**
Expand Down
25 changes: 25 additions & 0 deletions tests/PHPStan/Analyser/data/bug-1396.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php declare(strict_types = 1);

namespace Bug1396;

use PHPStan\Type\Constant\ConstantStringType;
use PHPStan\Type\ConstantScalarType;
use function PHPStan\Testing\assertType;

class HelloWorld
{
public function doFoo(
ConstantScalarType $constantType
): SpecifiedTypes
{
if ($constantType->getValue() === null) {
return new SpecifiedTypes();
}

if (
$constantType instanceof ConstantStringType
) {
assertType('string', $constantType->getValue());
}
}
}