Skip to content

Commit 2c6c726

Browse files
ondrejmirtesclaude
andcommitted
Throw the twin's error where native paths reported a failure with nothing pending
Several native paths returned their "exception pending" value without an exception, so the glue returned with nothing thrown (a caller then got null): IfHandler after warning about a foreign elseif or else, SwitchHandler and TryCatchHandler after warning about a non-array case, catch or catch-type list, TryCatchHandler after warning about a foreign finally, SimpleImpurePoint on a non-object scope, TypeSpecifier on a non-object nullsafe result, and PhpClassReflectionExtension on a non-array result of a call declared to return an array. Each now does what the twin does: warns and iterates nothing over a non-array list, throws the TypeError of the call the twin makes next (processExprNode(), processStmtNodesInternal(), callNodeCallback()), the "Call to a member function" Error, or the engine's return-type TypeError for a callee that broke its signature. SwitchHandler reads a foreign case's properties with the engine's warning instead of crashing, and IfHandler prints the undefined array key with ZEND_LONG_FMT. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018Fdg8n3eEi4ZoXa4dA2k4A
1 parent 51177a6 commit 2c6c726

7 files changed

Lines changed: 122 additions & 26 deletions

File tree

‎turbo-ext/src/IfHandler.cpp‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,11 @@ class IfHandler
209209
for (auto entry : zv::TableRef(iterated.table())) {
210210
zval *elseif = entry.value().deref().raw();
211211
if (UNEXPECTED(Z_TYPE_P(elseif) != IS_OBJECT)) {
212+
/* the twin reads null with a warning and hands it on */
212213
zend_error(E_WARNING, "Attempt to read property \"cond\" on %s", zend_zval_value_name(elseif));
214+
if (!EG(exception)) {
215+
zend_type_error("PHPStan\\Analyser\\NodeScopeResolver::processExprNode(): Argument #2 ($expr) must be of type PhpParser\\Node\\Expr, null given");
216+
}
213217
return zv::Val();
214218
}
215219
zval *elseifCond = ptsh::readNodeProperty(pt_ih_elseif_cond_site, elseif, PT_LC("cond"));
@@ -270,7 +274,12 @@ class IfHandler
270274
if (UNEXPECTED(elseNode == NULL)) return zv::Val();
271275
elseHold = zv::Val::copyOf(zv::Ref(elseNode));
272276
if (UNEXPECTED(Z_TYPE_P(elseHold.raw()) != IS_OBJECT)) {
277+
/* the twin reads null stmts with a warning and hands the
278+
* non-node on as the parent */
273279
zend_error(E_WARNING, "Attempt to read property \"stmts\" on %s", zend_zval_value_name(elseHold.raw()));
280+
if (!EG(exception)) {
281+
zend_type_error("PHPStan\\Analyser\\NodeScopeResolver::processStmtNodesInternal(): Argument #1 ($parentNode) must be of type PhpParser\\Node, %s given", zend_zval_value_name(elseHold.raw()));
282+
}
274283
return zv::Val();
275284
}
276285
zval *elseStmts = ptsh::readNodeProperty(pt_ih_else_stmts_site, elseHold.raw(), PT_LC("stmts"));
@@ -384,7 +393,7 @@ class IfHandler
384393
if (count > 0) {
385394
zval *last = zend_hash_index_find(Z_ARRVAL_P(stmts), (zend_ulong) (count - 1));
386395
if (UNEXPECTED(last == NULL)) {
387-
zend_error(E_WARNING, "Undefined array key %u", count - 1);
396+
zend_error(E_WARNING, "Undefined array key " ZEND_LONG_FMT, (zend_long) count - 1);
388397
if (UNEXPECTED(EG(exception))) return false;
389398
last = &EG(uninitialized_zval);
390399
} else {

‎turbo-ext/src/PhpClassReflectionExtension.cpp‎

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,17 @@ zv::Str ancestorMessage(zend_string *declaringClassName, zend_string *className)
169169
return zv::Str::adopt(zend_strpprintf(0, "Internal error: Expected to find an ancestor with class name %s on %s, but none was found.", ZSTR_VAL(declaringClassName), ZSTR_VAL(className)));
170170
}
171171

172+
/* the result of a call declared `: array`; false (an exception pending) when
173+
* the call threw or when the callee broke its signature — the engine's
174+
* return-type TypeError, which a PHP callee would have thrown itself */
175+
[[nodiscard]] bool arrayResult(zv::Val &result, const char *method)
176+
{
177+
if (UNEXPECTED(result.isUndef())) return false;
178+
if (EXPECTED(Z_TYPE_P(result.raw()) == IS_ARRAY)) return true;
179+
zend_type_error("%s(): Return value must be of type array, %s returned", method, zend_zval_value_name(result.raw()));
180+
return false;
181+
}
182+
172183
/* isset($array[$key]) over a symtable-keyed array: the value, or NULL when
173184
* the key is absent or holds null */
174185
zval *issetIn(zval *array, zend_string *key)
@@ -776,7 +787,7 @@ class PhpClassReflectionExtension
776787
zv::Val nativeType;
777788
if (declaringIsEnum) {
778789
zv::Val enumCases = call(classReflection, PT_LC("getenumcases"));
779-
if (UNEXPECTED(enumCases.isUndef()) || Z_TYPE_P(enumCases.raw()) != IS_ARRAY) return zv::Val();
790+
if (UNEXPECTED(!arrayResult(enumCases, "PHPStan\\Reflection\\ClassReflection::getEnumCases"))) return zv::Val();
780791
zv::Arr types = zv::Arr::create(zend_hash_num_elements(Z_ARRVAL_P(enumCases.raw())));
781792
for (zv::ArrayEntry entry : zv::ArrRef(enumCases.raw())) {
782793
if (isNameProperty) {
@@ -1557,7 +1568,7 @@ class PhpClassReflectionExtension
15571568
zv::Val builder = pt_constant_array_type_builder_create_empty();
15581569
if (UNEXPECTED(builder.isUndef())) return zv::Val();
15591570
zv::Val enumCases = call(classReflection, PT_LC("getenumcases"));
1560-
if (UNEXPECTED(enumCases.isUndef()) || Z_TYPE_P(enumCases.raw()) != IS_ARRAY) return zv::Val();
1571+
if (UNEXPECTED(!arrayResult(enumCases, "PHPStan\\Reflection\\ClassReflection::getEnumCases"))) return zv::Val();
15611572
zv::Val ownerName = pt_class_reflection_get_name(Z_OBJ_P(classReflection));
15621573
if (UNEXPECTED(ownerName.isUndef())) return zv::Val();
15631574
for (zv::ArrayEntry entry : zv::ArrRef(enumCases.raw())) {
@@ -1631,7 +1642,7 @@ class PhpClassReflectionExtension
16311642

16321643
zv::Args signatureArgs{declaringClassNameArg, methodNameArg, methodReflection};
16331644
zv::Val signaturesResult = call(slot(PT_PCRE_PROP_SIGNATURE_MAP_PROVIDER), PT_LC("getmethodsignatures"), 3, signatureArgs);
1634-
if (UNEXPECTED(signaturesResult.isUndef()) || Z_TYPE_P(signaturesResult.raw()) != IS_ARRAY) return zv::Val();
1645+
if (UNEXPECTED(!arrayResult(signaturesResult, "PHPStan\\Reflection\\SignatureMap\\SignatureMapProvider::getMethodSignatures"))) return zv::Val();
16351646

16361647
/* the twin reads $currentResolvedPhpDoc after the loops: the value
16371648
* the last inner iteration left, or null when none ran */
@@ -2177,7 +2188,7 @@ class PhpClassReflectionExtension
21772188
if (UNEXPECTED(!pt_method_adapter_is_constructor(methodReflection, isConstructor))) return zv::Val();
21782189
if (isConstructor) {
21792190
zv::Val parameters = call(methodReflection, PT_LC("getparameters"));
2180-
if (UNEXPECTED(parameters.isUndef()) || Z_TYPE_P(parameters.raw()) != IS_ARRAY) return zv::Val();
2191+
if (UNEXPECTED(!arrayResult(parameters, "PHPStan\\BetterReflection\\Reflection\\Adapter\\ReflectionMethod::getParameters"))) return zv::Val();
21812192
for (zv::ArrayEntry entry : zv::ArrRef(parameters.raw())) {
21822193
zval *parameter = entry.value().raw();
21832194
ZVAL_DEREF(parameter);
@@ -2234,7 +2245,7 @@ class PhpClassReflectionExtension
22342245
}
22352246
if (isBuiltin || actualIsEnum) {
22362247
zv::Val ancestors = call(actualDeclaringClass, PT_LC("getancestors"));
2237-
if (UNEXPECTED(ancestors.isUndef()) || Z_TYPE_P(ancestors.raw()) != IS_ARRAY) return zv::Val();
2248+
if (UNEXPECTED(!arrayResult(ancestors, "PHPStan\\Reflection\\ClassReflection::getAncestors"))) return zv::Val();
22382249
for (zv::ArrayEntry entry : zv::ArrRef(ancestors.raw())) {
22392250
zend_string *ancestorName = entry.stringKeyOrNull();
22402251
if (ancestorName == NULL) continue;
@@ -2516,7 +2527,7 @@ class PhpClassReflectionExtension
25162527
if (superType) return phpDocReturnType;
25172528
if (!isUnionType(phpDocReturnType.raw())) return zv::Val::null();
25182529
zv::Val innerTypes = pt_type_op(Z_OBJ_P(phpDocReturnType.raw()), PT_OP_GET_TYPES, 0, NULL);
2519-
if (UNEXPECTED(innerTypes.isUndef()) || Z_TYPE_P(innerTypes.raw()) != IS_ARRAY) return zv::Val();
2530+
if (UNEXPECTED(!arrayResult(innerTypes, "PHPStan\\Type\\UnionType::getTypes"))) return zv::Val();
25202531
zv::Arr kept = zv::Arr::create(zend_hash_num_elements(Z_ARRVAL_P(innerTypes.raw())));
25212532
for (zv::ArrayEntry entry : zv::ArrRef(innerTypes.raw())) {
25222533
bool accepted = isSuperTypeOfYes(nativeReturnType, entry.value().raw(), ok);
@@ -2559,7 +2570,7 @@ class PhpClassReflectionExtension
25592570
}
25602571

25612572
zv::Val ancestors = call(declaringClass, PT_LC("getancestors"));
2562-
if (UNEXPECTED(ancestors.isUndef()) || Z_TYPE_P(ancestors.raw()) != IS_ARRAY) return zv::Val();
2573+
if (UNEXPECTED(!arrayResult(ancestors, "PHPStan\\Reflection\\ClassReflection::getAncestors"))) return zv::Val();
25632574
for (zv::ArrayEntry entry : zv::ArrRef(ancestors.raw())) {
25642575
zval *ancestor = entry.value().raw();
25652576
ZVAL_DEREF(ancestor);
@@ -2783,7 +2794,7 @@ class PhpClassReflectionExtension
27832794
}
27842795
if (!instanceof_function(Z_OBJCE_P(node), namespaceCe) && !instanceof_function(Z_OBJCE_P(node), declareCe)) continue;
27852796
zv::Val subNodeNames = call(node, PT_LC("getsubnodenames"));
2786-
if (UNEXPECTED(subNodeNames.isUndef()) || Z_TYPE_P(subNodeNames.raw()) != IS_ARRAY) return zv::Val();
2797+
if (UNEXPECTED(!arrayResult(subNodeNames, "PhpParser\\Node::getSubNodeNames"))) return zv::Val();
27872798
for (zv::ArrayEntry nameEntry : zv::ArrRef(subNodeNames.raw())) {
27882799
zval *subNodeName = nameEntry.value().raw();
27892800
ZVAL_DEREF(subNodeName);

‎turbo-ext/src/SimpleImpurePoint.cpp‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,10 @@ class SimpleImpurePoint
334334

335335
zval *argValue = nodeProperty(pt_sip_arg_value_site, matchedArg, PT_LC("value"));
336336
if (UNEXPECTED(EG(exception))) return false;
337-
if (UNEXPECTED(Z_TYPE_P(scope) != IS_OBJECT)) return false;
337+
if (UNEXPECTED(Z_TYPE_P(scope) != IS_OBJECT)) {
338+
zend_throw_error(NULL, "Call to a member function getType() on %s", zend_zval_value_name(scope));
339+
return false;
340+
}
338341
zv::Val argType = pt_mutating_scope_get_type(Z_OBJ_P(scope), argValue);
339342
if (UNEXPECTED(argType.isUndef())) return false;
340343
zend_long isNull = pt_type_op_trinary(Z_OBJ_P(argType.raw()), PT_OP_IS_NULL, 0, NULL);

‎turbo-ext/src/SwitchHandler.cpp‎

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,17 @@ zv::Val getStartLine(zval *node)
4747
return pt_call_method_cached(pt_swh_get_start_line_site, Z_OBJ_P(node), PT_LC("getstartline"), 0, NULL);
4848
}
4949

50+
/* $caseNode->name of a case list element: a node's property, or — for an
51+
* element a hand-built Switch_ holds that is no object — the engine's
52+
* warning and null (NULL = the warning turned into an exception) */
53+
zval *caseProperty(pt_property_site &site, zval *caseNode, const char *name, size_t len)
54+
{
55+
if (EXPECTED(Z_TYPE_P(caseNode) == IS_OBJECT)) return ptsh::readNodeProperty(site, caseNode, name, len);
56+
zend_error(E_WARNING, "Attempt to read property \"%s\" on %s", name, zend_zval_value_name(caseNode));
57+
if (UNEXPECTED(EG(exception))) return NULL;
58+
return &EG(uninitialized_zval);
59+
}
60+
5061
} // namespace
5162

5263
namespace phpstanturbo {
@@ -118,29 +129,37 @@ class SwitchHandler
118129

119130
zval *cases = ptsh::readNodeProperty(pt_swh_cases_site, stmt, PT_LC("cases"));
120131
if (UNEXPECTED(cases == NULL)) return zv::Val();
121-
if (UNEXPECTED(Z_TYPE_P(cases) != IS_ARRAY)) {
122-
zend_error(E_WARNING, "foreach() argument must be of type array|object, %s given", zend_zval_value_name(cases));
123-
return zv::Val();
132+
/* the twin's two foreach loops over something else each warn and
133+
* iterate nothing (the typed property holds an array) */
134+
zv::Val casesValue = zv::Val::copyOf(zv::Ref(cases));
135+
bool casesIterable = Z_TYPE_P(casesValue.raw()) == IS_ARRAY;
136+
if (UNEXPECTED(!casesIterable)) {
137+
zend_error(E_WARNING, "foreach() argument must be of type array|object, %s given", zend_zval_value_name(casesValue.raw()));
138+
if (UNEXPECTED(EG(exception))) return zv::Val();
124139
}
125-
zv::Val casesHold = zv::Val::copyOf(zv::Ref(cases));
140+
zv::Val casesHold = casesIterable ? zv::Val::copyOf(casesValue.ref()) : zv::Val(zv::Arr::empty());
126141
/* the key of the last case with a condition ($lastNonDefaultCaseKey) */
127142
bool hasLastNonDefaultCase = false;
128143
zend_ulong lastNonDefaultIndex = 0;
129144
zend_string *lastNonDefaultKey = NULL;
130145
for (auto entry : zv::ArrRef(casesHold.raw())) {
131146
zval *caseNode = entry.value().deref().raw();
132-
zval *caseCond = ptsh::readNodeProperty(pt_swh_case_cond_site, caseNode, PT_LC("cond"));
147+
zval *caseCond = caseProperty(pt_swh_case_cond_site, caseNode, PT_LC("cond"));
133148
if (UNEXPECTED(caseCond == NULL)) return zv::Val();
134149
if (Z_TYPE_P(caseCond) == IS_NULL) continue;
135150
hasLastNonDefaultCase = true;
136151
lastNonDefaultKey = entry.stringKeyOrNull();
137152
lastNonDefaultIndex = entry.indexKey();
138153
}
139154

155+
if (UNEXPECTED(!casesIterable)) {
156+
zend_error(E_WARNING, "foreach() argument must be of type array|object, %s given", zend_zval_value_name(casesValue.raw()));
157+
if (UNEXPECTED(EG(exception))) return zv::Val();
158+
}
140159
zv::Val branchFinalScopeResult;
141160
for (auto entry : zv::ArrRef(casesHold.raw())) {
142161
zval *caseNode = entry.value().deref().raw();
143-
zval *caseCondSlot = ptsh::readNodeProperty(pt_swh_case_cond_site, caseNode, PT_LC("cond"));
162+
zval *caseCondSlot = caseProperty(pt_swh_case_cond_site, caseNode, PT_LC("cond"));
144163
if (UNEXPECTED(caseCondSlot == NULL)) return zv::Val();
145164
zv::Val caseCond = zv::Val::copyOf(zv::Ref(caseCondSlot));
146165
zv::Val branchScope;
@@ -222,9 +241,24 @@ class SwitchHandler
222241

223242
branchScope = pt_mutating_scope_merge_with(Z_OBJ_P(branchScope.raw()), prevScope.raw());
224243
if (UNEXPECTED(branchScope.isUndef())) return zv::Val();
225-
zval *caseStmts = ptsh::readNodeProperty(pt_swh_case_stmts_site, caseNode, PT_LC("stmts"));
244+
zval *caseStmts = caseProperty(pt_swh_case_stmts_site, caseNode, PT_LC("stmts"));
226245
if (UNEXPECTED(caseStmts == NULL)) return zv::Val();
227246
zv::Val caseStmtsHold = zv::Val::copyOf(zv::Ref(caseStmts));
247+
/* the twin's processStmtNodesInternal() parameter types, for a
248+
* hand-built case list's foreign element */
249+
{
250+
bool error = false;
251+
if (UNEXPECTED(!ptsh::isInstanceOf(caseNode, PT_CLASS_NODE, error))) {
252+
if (!error) {
253+
zend_type_error("PHPStan\\Analyser\\NodeScopeResolver::processStmtNodesInternal(): Argument #1 ($parentNode) must be of type PhpParser\\Node, %s given", zend_zval_value_name(caseNode));
254+
}
255+
return zv::Val();
256+
}
257+
if (UNEXPECTED(Z_TYPE_P(caseStmtsHold.raw()) != IS_ARRAY)) {
258+
zend_type_error("PHPStan\\Analyser\\NodeScopeResolver::processStmtNodesInternal(): Argument #2 ($stmts) must be of type array, %s given", zend_zval_value_name(caseStmtsHold.raw()));
259+
return zv::Val();
260+
}
261+
}
228262
zv::Val branchScopeResult = pt_node_scope_resolver_process_stmt_nodes_internal(nodeScopeResolver, caseNode, caseStmtsHold.raw(), branchScope.raw(), storage, nodeCallback, context);
229263
if (UNEXPECTED(branchScopeResult.isUndef())) return zv::Val();
230264
{

‎turbo-ext/src/TryCatchHandler.cpp‎

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -195,25 +195,40 @@ class TryCatchHandler
195195

196196
zval *catches = ptsh::readNodeProperty(pt_tch_catches_site, stmt, PT_LC("catches"));
197197
if (UNEXPECTED(catches == NULL)) return zv::Val();
198-
if (UNEXPECTED(Z_TYPE_P(catches) != IS_ARRAY)) {
198+
/* the twin's foreach over something else warns and iterates nothing
199+
* (the typed property holds an array) */
200+
bool catchesIterable = Z_TYPE_P(catches) == IS_ARRAY;
201+
if (UNEXPECTED(!catchesIterable)) {
199202
zend_error(E_WARNING, "foreach() argument must be of type array|object, %s given", zend_zval_value_name(catches));
200-
return zv::Val();
203+
if (UNEXPECTED(EG(exception))) return zv::Val();
201204
}
202-
zv::Val catchesHold = zv::Val::copyOf(zv::Ref(catches));
205+
zv::Val catchesHold = catchesIterable ? zv::Val::copyOf(zv::Ref(catches)) : zv::Val(zv::Arr::empty());
203206
for (auto catchEntry : zv::ArrRef(catchesHold.raw())) {
204207
zval *catchNode = catchEntry.value().deref().raw();
208+
/* the twin's callNodeCallback() parameter type, for a hand-built
209+
* catch list's foreign element */
210+
{
211+
bool error = false;
212+
if (UNEXPECTED(!ptsh::isInstanceOf(catchNode, PT_CLASS_NODE, error))) {
213+
if (!error) {
214+
zend_type_error("PHPStan\\Analyser\\NodeScopeResolver::callNodeCallback(): Argument #2 ($node) must be of type PhpParser\\Node, %s given", zend_zval_value_name(catchNode));
215+
}
216+
return zv::Val();
217+
}
218+
}
205219
if (UNEXPECTED(!pt_node_scope_resolver_call_node_callback(nodeScopeResolver, nodeCallback, catchNode, scope, storage))) return zv::Val();
206220

207221
zv::Arr originalCatchTypes = zv::Arr::empty();
208222
zv::Arr catchTypes = zv::Arr::empty();
209223
{
210224
zval *types = ptsh::readNodeProperty(pt_tch_catch_types_site, catchNode, PT_LC("types"));
211225
if (UNEXPECTED(types == NULL)) return zv::Val();
212-
if (UNEXPECTED(Z_TYPE_P(types) != IS_ARRAY)) {
226+
bool typesIterable = Z_TYPE_P(types) == IS_ARRAY;
227+
if (UNEXPECTED(!typesIterable)) {
213228
zend_error(E_WARNING, "foreach() argument must be of type array|object, %s given", zend_zval_value_name(types));
214-
return zv::Val();
229+
if (UNEXPECTED(EG(exception))) return zv::Val();
215230
}
216-
zv::Val typesHold = zv::Val::copyOf(zv::Ref(types));
231+
zv::Val typesHold = typesIterable ? zv::Val::copyOf(zv::Ref(types)) : zv::Val(zv::Arr::empty());
217232
for (auto typeEntry : zv::ArrRef(typesHold.raw())) {
218233
zval *catchNodeType = typeEntry.value().deref().raw();
219234
if (UNEXPECTED(Z_TYPE_P(catchNodeType) != IS_OBJECT)) {
@@ -568,7 +583,12 @@ class TryCatchHandler
568583
if (UNEXPECTED(finallyNow == NULL)) return zv::Val();
569584
zv::Val finallyHold = zv::Val::copyOf(zv::Ref(finallyNow));
570585
if (UNEXPECTED(Z_TYPE_P(finallyHold.raw()) != IS_OBJECT)) {
586+
/* the twin reads null stmts with a warning and hands the
587+
* non-node on as the parent */
571588
zend_error(E_WARNING, "Attempt to read property \"stmts\" on %s", zend_zval_value_name(finallyHold.raw()));
589+
if (!EG(exception)) {
590+
zend_type_error("PHPStan\\Analyser\\NodeScopeResolver::processStmtNodesInternal(): Argument #1 ($parentNode) must be of type PhpParser\\Node, %s given", zend_zval_value_name(finallyHold.raw()));
591+
}
572592
return zv::Val();
573593
}
574594
zval *finallyStmts = ptsh::readNodeProperty(pt_tch_finally_stmts_site, finallyHold.raw(), PT_LC("stmts"));

‎turbo-ext/src/TypeSpecifier.cpp‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,10 @@ class TypeSpecifier
642642
if (containsNull == 0) {
643643
zv::Val nullsafeTypes = createNullsafeTypes(originalExpr, scope, context, type);
644644
if (UNEXPECTED(nullsafeTypes.isUndef())) return zv::Val();
645-
if (UNEXPECTED(Z_TYPE_P(nullsafeTypes.raw()) != IS_OBJECT)) return zv::Val();
645+
if (UNEXPECTED(Z_TYPE_P(nullsafeTypes.raw()) != IS_OBJECT)) {
646+
zend_throw_error(NULL, "Call to a member function unionWith() on %s", zend_zval_value_name(nullsafeTypes.raw()));
647+
return zv::Val();
648+
}
646649
return pt_specified_types_union_with(Z_OBJ_P(nullsafeTypes.raw()), types.raw());
647650
}
648651

‎turbo-ext/tests/smoke.php‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4402,12 +4402,23 @@ public function getComments(): array
44024402
$containerFactory = new \PHPStan\DependencyInjection\ContainerFactory($root);
44034403
$container = $containerFactory->create(sys_get_temp_dir() . '/phpstan-turbo-smoke-lane-engine', [$containerFactory->getConfigDirectory() . '/config.level8.neon'], []);
44044404
$outcome = static function (callable $callback): array {
4405+
$warnings = [];
4406+
set_error_handler(static function (int $level, string $message) use (&$warnings): bool {
4407+
$warnings[] = [$level, $message];
4408+
return true;
4409+
});
44054410
try {
44064411
$value = $callback();
4407-
return ['ok', is_object($value) ? get_class($value) : $value];
4412+
$result = ['ok', is_object($value) ? get_class($value) : $value];
44084413
} catch (\Throwable $e) {
4409-
return [get_class($e), preg_replace('~, called in .*$~', '', $e->getMessage())];
4414+
$result = [get_class($e), preg_replace('~, called in .*$~', '', $e->getMessage())];
4415+
} finally {
4416+
restore_error_handler();
44104417
}
4418+
if ($warnings !== []) {
4419+
$result[] = $warnings;
4420+
}
4421+
return $result;
44114422
};
44124423
$scope = $container->getByType(\PHPStan\Analyser\ScopeFactory::class)->create(\PHPStan\Analyser\ScopeContext::create(__FILE__));
44134424
$probes = (static function () use ($container, $outcome, $scope): array {
@@ -4438,6 +4449,11 @@ public function getComments(): array
44384449
'doProcessStmtNodes(stdClass)' => $outcome(static fn () => $doProcess([new \stdClass()])),
44394450
'doProcessStmtNodes(string)' => $outcome(static fn () => $doProcess(['echo'])),
44404451
'doProcessStmtNodes(expr)' => $outcome(static fn () => $doProcess([new \PhpParser\Node\Expr\Variable('x')])),
4452+
// statement nodes built by hand with foreign elements
4453+
'if with a foreign elseif' => $outcome(static fn () => $doProcess([new \PhpParser\Node\Stmt\If_(new \PhpParser\Node\Expr\Variable('x'), ['elseifs' => ['elseif']])])),
4454+
'switch with a foreign case' => $outcome(static fn () => $doProcess([new \PhpParser\Node\Stmt\Switch_(new \PhpParser\Node\Expr\Variable('x'), ['case'])])),
4455+
'try with a foreign catch' => $outcome(static fn () => $doProcess([new \PhpParser\Node\Stmt\TryCatch([], ['catch'])])),
4456+
'try with a foreign catch type' => $outcome(static fn () => $doProcess([new \PhpParser\Node\Stmt\TryCatch([], [new \PhpParser\Node\Stmt\Catch_(['type'])])])),
44414457
] + (static function () use ($container, $outcome, $scope, $nodeScopeResolver): array {
44424458
// the @api entry points of TypeSpecifier and PropertyHooksProcessor
44434459
$typeSpecifier = $container->getByType(\PHPStan\Analyser\TypeSpecifier::class);

0 commit comments

Comments
 (0)