Skip to content

Commit bc52fbe

Browse files
authored
Merge branch refs/heads/1.11.x into 1.12.x
2 parents b42db0e + 52d6a89 commit bc52fbe

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

src/Reflection/InitializerExprTypeResolver.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1095,9 +1095,17 @@ public function getPlusType(Expr $left, Expr $right, callable $getTypeCallback):
10951095
new BooleanType(),
10961096
]);
10971097

1098-
if ($plusable->isSuperTypeOf($leftType)->yes() && $plusable->isSuperTypeOf($rightType)->yes()) {
1098+
$plusableSuperTypeOfLeft = $plusable->isSuperTypeOf($leftType)->yes();
1099+
$plusableSuperTypeOfRight = $plusable->isSuperTypeOf($rightType)->yes();
1100+
if ($plusableSuperTypeOfLeft && $plusableSuperTypeOfRight) {
10991101
return TypeCombinator::union($leftType, $rightType);
11001102
}
1103+
if ($plusableSuperTypeOfLeft && $rightType instanceof MixedType) {
1104+
return $leftType;
1105+
}
1106+
if ($plusableSuperTypeOfRight && $leftType instanceof MixedType) {
1107+
return $rightType;
1108+
}
11011109
}
11021110

11031111
return $this->resolveCommonMath(new BinaryOp\Plus($left, $right), $leftType, $rightType);

tests/PHPStan/Rules/Methods/ReturnTypeRuleTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,4 +1039,9 @@ public function testBug11491(): void
10391039
$this->analyse([__DIR__ . '/data/bug-11491.php'], []);
10401040
}
10411041

1042+
public function testBug3759(): void
1043+
{
1044+
$this->analyse([__DIR__ . '/data/bug-3759.php'], []);
1045+
}
1046+
10421047
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug3759;
4+
5+
class A
6+
{
7+
/**
8+
* @return mixed[]
9+
*/
10+
function modules(): array
11+
{
12+
$modules = moduleList();
13+
if (!$modules) {
14+
return [];
15+
}
16+
17+
return $modules['major'] + $modules['minor'] + $modules['patch'];
18+
}
19+
20+
/**
21+
* @return mixed[]
22+
*/
23+
function moduleList(): array
24+
{
25+
return [
26+
'major' => ['x' => 'x'],
27+
'minor' => ['y' => 'y'],
28+
'patch' => ['z' => 'z'],
29+
];
30+
}
31+
}

0 commit comments

Comments
 (0)