Skip to content

Commit d945840

Browse files
authored
[NodeTypeResolver] Apply logic Mixed inside Union check on TypeFactory::createUnionOrSingleType() (#7345)
* [NodeTypeResolver] Apply logic Mixed inside Union check on TypeFactory::createUnionOrSingleType() * [NodeTypeResolver] Apply logic Mixed inside Union check on TypeFactory::createUnionOrSingleType()
1 parent c5b8eba commit d945840

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

rules/TypeDeclaration/NodeAnalyzer/CallTypesResolver.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,9 @@ private function unionToSingleType(array $staticTypesByArgumentPosition, bool $r
127127
$unionedType
128128
);
129129

130-
if ($staticTypeByArgumentPosition[$position] instanceof UnionType) {
130+
if ($removeMixedArray && $staticTypeByArgumentPosition[$position] instanceof UnionType) {
131131
foreach ($staticTypeByArgumentPosition[$position]->getTypes() as $subType) {
132-
// has another type over mixed is not allowed, even on native type
133-
if ($subType instanceof MixedType) {
134-
$staticTypeByArgumentPosition[$position] = new MixedType();
135-
continue 2;
136-
}
137-
138-
if ($removeMixedArray && $subType instanceof ArrayType && $this->isArrayMixedMixedType($subType)) {
132+
if ($subType instanceof ArrayType && $this->isArrayMixedMixedType($subType)) {
139133
$staticTypeByArgumentPosition[$position] = new MixedType();
140134
continue 2;
141135
}

src/NodeTypeResolver/PHPStan/Type/TypeFactory.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,12 @@ private function createUnionOrSingleType(array $types): Type
168168
return $types[0];
169169
}
170170

171+
foreach ($types as $type) {
172+
if ($type instanceof MixedType) {
173+
return new MixedType();
174+
}
175+
}
176+
171177
return new UnionType($types);
172178
}
173179

0 commit comments

Comments
 (0)