Skip to content
Open
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
6 changes: 4 additions & 2 deletions src/Analyser/ExprHandler/AssignHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -1721,6 +1721,8 @@ public function applyWrite(
$impurePoints = array_merge($impurePoints, $result->getImpurePoints());
$isAlwaysTerminating = $result->isAlwaysTerminating();
$scope = $result->getScope();
$assignedExprType = $this->readAssignedValueType($nodeScopeResolver, $assignedValueResult, $assignedExpr, $scope);
$assignedExprNativeType = $this->readAssignedValueType($nodeScopeResolver, $assignedValueResult, $assignedExpr, $scope->doNotTreatPhpDocTypesAsCertain());
foreach ($var->items as $i => $arrayItem) {
if ($arrayItem === null) {
continue;
Expand Down Expand Up @@ -1753,8 +1755,8 @@ public function applyWrite(
$nativeDimType = $dimType;
}
$getOffsetValueTypeExpr = new NativeTypeExpr(
$this->readAssignedValueType($nodeScopeResolver, $assignedValueResult, $assignedExpr, $scope)->getOffsetValueType($dimType),
$this->readAssignedValueType($nodeScopeResolver, $assignedValueResult, $assignedExpr, $scope->doNotTreatPhpDocTypesAsCertain())->getOffsetValueType($nativeDimType),
$assignedExprType->getOffsetValueType($dimType),
$assignedExprNativeType->getOffsetValueType($nativeDimType),
);
// store the fabricated result so narrowing walks over the item value
// compose from it instead of falling back to on-demand pricing
Expand Down
2 changes: 1 addition & 1 deletion src/Turbo/TurboExtensionEnabler.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
final class TurboExtensionEnabler
{

public const EXPECTED_EXTENSION_VERSION = '1cb5faf';
public const EXPECTED_EXTENSION_VERSION = '3e0dc8a';

private static bool $active = false;

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

namespace Bug15091;

use function PHPStan\Testing\assertNativeType;
use function PHPStan\Testing\assertType;

function reassignFirstListItem(): void
{
$values = ['foo', 'bar'];
[$values, $second] = $values;
assertType("'bar'", $second);
assertNativeType("'bar'", $second);
}

function reassignFirstKeyedItem(): void
{
$values = ['first' => 1, 'second' => 'value'];
['first' => $values, 'second' => $second] = $values;
assertType("'value'", $second);
}

function reassignNestedItem(): void
{
$values = [['inner', 42], 'last'];
[[$values, $number], $last] = $values;
assertType('42', $number);
assertType("'last'", $last);
}

/** @param array{string, callable(): int} $value */
function callableSecond(array $value): void
{
[$value, $callable] = $value;
assertType('callable(): int', $callable);
assertNativeType('mixed', $callable);
assertType('string', $value);
assertNativeType('mixed', $value);
}

function sourceInLaterTarget(): void
{
$values = ['first', 'second'];
[$first, $values] = $values;
assertType("'first'", $first);
assertType("'second'", $values);
}

function skipSlotAfterReassigningSource(): void
{
$values = ['first', 'skipped', 'third'];
[$values, , $third] = $values;
assertType("'third'", $third);
}

function withoutReassigningSource(): void
{
$values = ['first', 'second'];
[$first, $second] = $values;
assertType("'first'", $first);
assertNativeType("'first'", $first);
assertType("'second'", $second);
}
10 changes: 5 additions & 5 deletions turbo-ext/src/AssignHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4034,6 +4034,9 @@ class AssignHandler
}
AH_OKB(pt_expression_result_is_always_terminating(result, isAlwaysTerminating));
AH_SETB(scope, ahResultScope(result));
AH_VALB(assignedExprType, readAssignedValueType(nsr, assignedValueResult, assignedExpr, scope.raw()));
AH_VALB(nativeScope, pt_mutating_scope_do_not_treat_phpdoc_types_as_certain(Z_OBJ_P(scope.raw())));
AH_VALB(assignedExprNativeType, readAssignedValueType(nsr, assignedValueResult, assignedExpr, nativeScope.raw()));
zval *items = AH_PROP(var, items);
if (Z_TYPE_P(items) != IS_ARRAY) return true;
zv::Val itemsHolder = zv::Val::copyOf(zv::Ref(items));
Expand Down Expand Up @@ -4081,11 +4084,8 @@ class AssignHandler
AH_SETB(dimType, newConstantIntegerType((zend_long) entry.indexKey()));
nativeDimType = zv::Val::copyOf(dimType.ref());
}
AH_VALB(valueType, readAssignedValueType(nsr, assignedValueResult, assignedExpr, scope.raw()));
AH_VALB(offsetValueType, ahTypeOp(valueType.raw(), PT_OP_GET_OFFSET_VALUE_TYPE, 1, dimType.raw()));
AH_VALB(nativeItemScope, pt_mutating_scope_do_not_treat_phpdoc_types_as_certain(Z_OBJ_P(scope.raw())));
AH_VALB(nativeValueType, readAssignedValueType(nsr, assignedValueResult, assignedExpr, nativeItemScope.raw()));
AH_VALB(nativeOffsetValueType, ahTypeOp(nativeValueType.raw(), PT_OP_GET_OFFSET_VALUE_TYPE, 1, nativeDimType.raw()));
AH_VALB(offsetValueType, ahTypeOp(assignedExprType.raw(), PT_OP_GET_OFFSET_VALUE_TYPE, 1, dimType.raw()));
AH_VALB(nativeOffsetValueType, ahTypeOp(assignedExprNativeType.raw(), PT_OP_GET_OFFSET_VALUE_TYPE, 1, nativeDimType.raw()));
AH_VALB(getOffsetValueTypeExpr, newNativeTypeExpr(offsetValueType.raw(), nativeOffsetValueType.raw()));
// store the fabricated result so narrowing walks over the item value
// compose from it instead of falling back to on-demand pricing
Expand Down
Loading