Skip to content

Commit 3d069e0

Browse files
clxmstaabondrejmirtes
authored andcommitted
fix
1 parent dfb47d7 commit 3d069e0

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

src/Analyser/MutatingScope.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,7 +1102,7 @@ private function resolveType(Expr $node): Type
11021102
}
11031103

11041104
// we limit the number of union-types for performance reasons
1105-
if ($leftStringType instanceof UnionType && count($leftStringType->getTypes()) < 32 && $rightStringType instanceof ConstantStringType) {
1105+
if ($leftStringType instanceof UnionType && count($leftStringType->getTypes()) <= 16 && $rightStringType instanceof ConstantStringType) {
11061106
$constantStrings = TypeUtils::getConstantStrings($leftStringType);
11071107
if (count($constantStrings) > 0) {
11081108
$strings = [];
@@ -1113,7 +1113,7 @@ private function resolveType(Expr $node): Type
11131113
return TypeCombinator::union(...$strings);
11141114
}
11151115
}
1116-
if ($rightStringType instanceof UnionType && count($rightStringType->getTypes()) < 32 && $leftStringType instanceof ConstantStringType) {
1116+
if ($rightStringType instanceof UnionType && count($rightStringType->getTypes()) <= 16 && $leftStringType instanceof ConstantStringType) {
11171117
$constantStrings = TypeUtils::getConstantStrings($rightStringType);
11181118
if (count($constantStrings) > 0) {
11191119
$strings = [];

tests/PHPStan/Analyser/data/bug-6439.php

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,30 +34,29 @@ public function unionOnRight(string $name, ?int $gesperrt = null, ?int $adaid =
3434
}
3535

3636
public function testLimit() {
37-
$string = 'i';
37+
$string = '0';
3838

3939
if (rand(0,1)) {
40-
$string .= ' a';
40+
$string .= 'a';
4141
}
4242
if (rand(0,1)) {
43-
$string .= ' b';
43+
$string .= 'b';
4444
}
4545
if (rand(0,1)) {
46-
$string .= ' c';
46+
$string .= 'c';
4747
}
4848
if (rand(0,1)) {
49-
$string .= ' d';
49+
$string .= 'd';
5050
}
5151
if (rand(0,1)) {
52-
$string .= ' e';
53-
}
54-
assertType("'i'|'i a'|'i a b'|'i a b c'|'i a b c d'|'i a b c d e'|'i a b c e'|'i a b d'|'i a b d e'|'i a b e'|'i a c'|'i a c d'|'i a c d e'|'i a c e'|'i a d'|'i a d e'|'i a e'|'i b'|'i b c'|'i b c d'|'i b c d e'|'i b c e'|'i b d'|'i b d e'|'i b e'|'i c'|'i c d'|'i c d e'|'i c e'|'i d'|'i d e'|'i e'", $string);
52+
$string .= 'e';
5553

56-
if (rand(0,1)) {
57-
$string .= ' f';
58-
}
59-
60-
assertType("literal-string&non-empty-string", $string);
54+
// union should contain 32 elements
55+
assertType("'0'|'0a'|'0ab'|'0abc'|'0abcd'|'0abcde'|'0abce'|'0abd'|'0abde'|'0abe'|'0ac'|'0acd'|'0acde'|'0ace'|'0ad'|'0ade'|'0ae'|'0b'|'0bc'|'0bcd'|'0bcde'|'0bce'|'0bd'|'0bde'|'0be'|'0c'|'0cd'|'0cde'|'0ce'|'0d'|'0de'|'0e'", $string);
6156

57+
// adding more elements should fallback to the more general form
58+
$string .= 'too-long';
59+
assertType("literal-string&non-empty-string", $string);
60+
}
6261
}
6362
}

0 commit comments

Comments
 (0)