Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Analyser/MutatingScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -4731,7 +4731,7 @@ private function mergeSameGuardConditionalExpressions(
$ourGuards,
new ExpressionTypeHolder(
$ourTypeHolder->getExpr(),
TypeCombinator::union($ourTypeHolder->getType(), $theirTypeHolder->getType()),
TypeCombinator::widen(TypeCombinator::union($ourTypeHolder->getType(), $theirTypeHolder->getType())),
$ourTypeHolder->getCertainty(),
),
);
Expand Down
97 changes: 97 additions & 0 deletions tests/bench/data/bug-15862.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?php declare(strict_types = 1);

/*
* instructions: 22.08B
* cycles: 25.64B
* memory: 8.009MiB
*/

namespace Bug15862;

/** @param array<mixed> $rows */
function f(array $rows): void {
$r = [
'T_7' => 0,
'T_30' => 0,
'T_90' => 0,
'C0_7' => 0,
'C0_30' => 0,
'C0_90' => 0,
'C1_7' => 0,
'C1_30' => 0,
'C1_90' => 0,
'C2_7' => 0,
'C2_30' => 0,
'C2_90' => 0,
'C3_7' => 0,
'C3_30' => 0,
'C3_90' => 0,
];
foreach ($rows as $row) {
$a = $row['a'] ?? false;
$b = $row['b'] ?? false;
$c = $row['c'] ?? false;
$s = $row['s'] ?? false;
if ($a) {
$r['T_7']++;
$r['T_30']++;
$r['T_90']++;
} elseif ($b) {
$r['T_30']++;
$r['T_90']++;
} elseif ($c) {
$r['T_90']++;
}
switch ($row['t']) {
case 'c0':
if ($a) {
$r['C0_7']++;
$r['C0_30']++;
$r['C0_90']++;
} elseif ($b) {
$r['C0_30']++;
$r['C0_90']++;
} elseif ($c) {
$r['C0_90']++;
}
break;
case 'c1':
if ($a) {
$r['C1_7']++;
$r['C1_30']++;
$r['C1_90']++;
} elseif ($b) {
$r['C1_30']++;
$r['C1_90']++;
} elseif ($c) {
$r['C1_90']++;
}
break;
case 'c2':
if ($a) {
$r['C2_7']++;
$r['C2_30']++;
$r['C2_90']++;
} elseif ($b) {
$r['C2_30']++;
$r['C2_90']++;
} elseif ($c) {
$r['C2_90']++;
}
break;
case 'c3':
if ($a) {
$r['C3_7']++;
$r['C3_30']++;
$r['C3_90']++;
} elseif ($b) {
$r['C3_30']++;
$r['C3_90']++;
} elseif ($c) {
$r['C3_90']++;
}
break;
}
}
\PHPStan\dumpType($r);
}
5 changes: 4 additions & 1 deletion turbo-ext/src/MutatingScope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8961,7 +8961,10 @@ class MutatingScope
zv::Val theirType = holderType(theirTypeHolder.ref());
zv::Val ourExpr = holderExpr(ourTypeHolder.ref());
if (UNEXPECTED(ourType.isUndef() || theirType.isUndef() || ourExpr.isUndef())) return zv::Val();
zv::Val united = unionTypes(ourType.raw(), theirType.raw());
/* TypeCombinator::widen(TypeCombinator::union(...)): a join of branches, widened like the joins of scopes */
zv::Val joined = unionTypes(ourType.raw(), theirType.raw());
if (UNEXPECTED(joined.isUndef())) return zv::Val();
zv::Val united = pt_type_combinator_call(PT_LC("widen"), 1, joined.raw());
if (UNEXPECTED(united.isUndef())) return zv::Val();
zval typeHolder;
pt_holder_create(&typeHolder, ourExpr.raw(), united.raw(), ourCertainty);
Expand Down
Loading