Skip to content

Commit ad53698

Browse files
committed
MutatingScope: Remove unnecessary union
1 parent 0296a80 commit ad53698

File tree

5 files changed

+6
-19
lines changed

5 files changed

+6
-19
lines changed

src/Analyser/MutatingScope.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3343,16 +3343,7 @@ public function specifyExpressionType(Expr $expr, Type $type, Type $nativeType,
33433343
if ($dimType->isInteger()->yes() || $dimType->isString()->yes()) {
33443344
$exprVarType = $scope->getType($expr->var);
33453345
if (!$exprVarType instanceof MixedType && !$exprVarType->isArray()->no()) {
3346-
$types = [
3347-
new ArrayType(new MixedType(), new MixedType()),
3348-
new ObjectType(ArrayAccess::class),
3349-
new NullType(),
3350-
];
3351-
if ($dimType->isInteger()->yes()) {
3352-
$types[] = new StringType();
3353-
}
3354-
$offsetValueType = TypeCombinator::intersect($exprVarType, TypeCombinator::union(...$types));
3355-
3346+
$offsetValueType = $exprVarType;
33563347
if ($dimType instanceof ConstantIntegerType || $dimType instanceof ConstantStringType) {
33573348
$offsetValueType = TypeCombinator::intersect(
33583349
$offsetValueType,

src/Type/Accessory/NonEmptyArrayType.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,6 @@ public function getConstantStrings(): array
7676

7777
public function accepts(Type $type, bool $strictTypes): AcceptsResult
7878
{
79-
if ($type instanceof CompoundType) {
80-
return $type->isAcceptedBy($this, $strictTypes);
81-
}
82-
8379
$isArray = $type->isArray();
8480
$isIterableAtLeastOnce = $type->isIterableAtLeastOnce();
8581

tests/PHPStan/Analyser/nsrt/composer-array-bug.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,17 @@ public function doFoo(): void
4747
}
4848
}
4949

50-
assertType("non-empty-array&hasOffsetValue('authors', mixed)", $this->config);
50+
assertType("non-empty-array<mixed>&hasOffsetValue('authors', mixed)", $this->config);
5151
assertType("mixed", $this->config['authors']);
5252

5353
if (empty($this->config['authors'])) {
5454
unset($this->config['authors']);
5555
assertType("array<mixed~'authors', mixed>", $this->config);
5656
} else {
57-
assertType("non-empty-array&hasOffsetValue('authors', mixed~(0|0.0|''|'0'|array{}|false|null))", $this->config);
57+
assertType("non-empty-array<mixed>&hasOffsetValue('authors', mixed~(0|0.0|''|'0'|array{}|false|null))", $this->config);
5858
}
5959

60-
assertType("array", $this->config);
60+
assertType("array<mixed>", $this->config);
6161
}
6262
}
6363

tests/PHPStan/Analyser/nsrt/superglobals.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function canBePartlyOverwritten(): void
3838
public function canBeNarrowed(): void
3939
{
4040
if (isset($GLOBALS['foo'])) {
41-
assertType("non-empty-array&hasOffsetValue('foo', mixed~null)", $GLOBALS);
41+
assertType("non-empty-array<mixed>&hasOffsetValue('foo', mixed~null)", $GLOBALS);
4242
assertNativeType("non-empty-array<mixed>&hasOffset('foo')", $GLOBALS); // https://github.com/phpstan/phpstan/issues/8395
4343
} else {
4444
assertType('array<mixed>', $GLOBALS);

tests/PHPStan/Rules/Functions/data/bug-7156.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function foobar2(mixed $data): void
3232
throw new \RuntimeException();
3333
}
3434

35-
assertType("non-empty-array&hasOffsetValue('value', string)", $data);
35+
assertType("non-empty-array<mixed, mixed>&hasOffsetValue('value', string)", $data);
3636

3737
foo($data);
3838
}

0 commit comments

Comments
 (0)