Skip to content

Commit 580fb36

Browse files
Simplified ArrayType with Mixed
1 parent 5e3a364 commit 580fb36

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

src/Type/ArrayType.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use PHPStan\Type\Constant\ConstantIntegerType;
2222
use PHPStan\Type\Constant\ConstantStringType;
2323
use PHPStan\Type\Generic\TemplateMixedType;
24+
use PHPStan\Type\Generic\TemplateStrictMixedType;
2425
use PHPStan\Type\Generic\TemplateTypeMap;
2526
use PHPStan\Type\Generic\TemplateTypeVariance;
2627
use PHPStan\Type\Traits\MaybeCallableTypeTrait;
@@ -50,6 +51,10 @@ public function __construct(Type $keyType, private Type $itemType)
5051
if ($keyType->describe(VerbosityLevel::value()) === '(int|string)') {
5152
$keyType = new MixedType();
5253
}
54+
if ($keyType instanceof StrictMixedType && !$keyType instanceof TemplateStrictMixedType) {
55+
$keyType = new UnionType([new StringType(), new IntegerType()]);
56+
}
57+
5358
$this->keyType = $keyType;
5459
}
5560

tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,14 @@ class CallToFunctionParametersRuleTest extends RuleTestCase
2020
{
2121

2222
private bool $checkExplicitMixed = false;
23+
private bool $checkImplicitMixed = false;
2324

2425
protected function getRule(): Rule
2526
{
2627
$broker = $this->createReflectionProvider();
2728
return new CallToFunctionParametersRule(
2829
$broker,
29-
new FunctionCallParametersCheck(new RuleLevelHelper($broker, true, false, true, $this->checkExplicitMixed, false, true, false), new NullsafeCheck(), new PhpVersion(80000), new UnresolvableTypeHelper(), new PropertyReflectionFinder(), true, true, true, true, true),
30+
new FunctionCallParametersCheck(new RuleLevelHelper($broker, true, false, true, $this->checkExplicitMixed, $this->checkImplicitMixed, true, false), new NullsafeCheck(), new PhpVersion(80000), new UnresolvableTypeHelper(), new PropertyReflectionFinder(), true, true, true, true, true),
3031
);
3132
}
3233

@@ -1903,4 +1904,11 @@ public function testBug11759(): void
19031904
$this->analyse([__DIR__ . '/data/bug-11759.php'], []);
19041905
}
19051906

1907+
public function testBug12051(): void
1908+
{
1909+
$this->checkExplicitMixed = true;
1910+
$this->checkImplicitMixed = true;
1911+
$this->analyse([__DIR__ . '/data/bug-12051.php'], []);
1912+
}
1913+
19061914
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace Bug12051;
4+
5+
/** @param array<int|string, mixed> $a */
6+
function foo($a): void {
7+
print "ok\n";
8+
}
9+
10+
/**
11+
* @param array<mixed> $a
12+
*/
13+
function bar($a): void {
14+
foo($a);
15+
}

0 commit comments

Comments
 (0)