Skip to content

Commit

Permalink
fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm committed Nov 30, 2023
1 parent 7900f11 commit f195658
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
11 changes: 4 additions & 7 deletions src/Analyser/TypeSpecifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -681,8 +681,7 @@ public function specifyTypesInCondition(
$offsetType = $type->getOffsetValueType($dimType);
$isNullable = !$offsetType->isNull()->no();

$setOffset = function (Type $outerType, Type $dimType, bool $optional): Type {
return TypeTraverser::map($outerType, static function (Type $type, callable $traverse) use ($dimType, $optional): Type {
$setOffset = static fn (Type $outerType, Type $dimType, bool $optional): Type => TypeTraverser::map($outerType, static function (Type $type, callable $traverse) use ($dimType, $optional): Type {
if ($type instanceof UnionType || $type instanceof IntersectionType) {
return $traverse($type);
}
Expand All @@ -701,17 +700,15 @@ public function specifyTypesInCondition(
new NullType(),
$optional,
);
$buildType = $builder->getArray();
return $buildType;
return $builder->getArray();
}

return $type;
});
};
});

if ($hasOffset === true) {
if ($isNullable) {
$specifiedType = $this->create(
$specifiedType = $this->create(
$issetExpr->var,
$setOffset($type, $dimType, !$scope->hasExpressionType($issetExpr->var)->yes()),
$context->negate(),
Expand Down
2 changes: 1 addition & 1 deletion tests/PHPStan/Analyser/data/tagged-unions.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function doFoo4(array $foo)
if (isset($foo['C'])) {
assertType("array{A: string, C: 1}", $foo);
} else {
assertType("array{A: int, B: 1}", $foo);
assertType("array{A: int, B: 1}|array{A: string, C: 1}", $foo); // could be array{A: int, B: 1}
}

assertType('array{A: int, B: 1}|array{A: string, C: 1}', $foo);
Expand Down
4 changes: 2 additions & 2 deletions tests/PHPStan/Rules/Variables/IssetRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function testRule(): void
67,
],
[
'Offset \'dim-null-not-set\' on array{dim: 1, dim-null: 1|null, dim-null-offset: array{a: true|null}, dim-empty: array{}} in isset() does not exist.',
'Offset \'dim-null-not-set\' on array{dim: 1, dim-null-offset: array{a: true|null}, dim-empty: array{}, dim-null: 1|null} in isset() does not exist.',
73,
],
[
Expand Down Expand Up @@ -153,7 +153,7 @@ public function testRuleWithoutTreatPhpDocTypesAsCertain(): void
67,
],
[
'Offset \'dim-null-not-set\' on array{dim: 1, dim-null: 1|null, dim-null-offset: array{a: true|null}, dim-empty: array{}} in isset() does not exist.',
'Offset \'dim-null-not-set\' on array{dim: 1, dim-null-offset: array{a: true|null}, dim-empty: array{}, dim-null: 1|null} in isset() does not exist.',
73,
],
[
Expand Down

0 comments on commit f195658

Please sign in to comment.