@@ -33,10 +33,6 @@ namespace {
3333pt_property_site pt_exh_expression_expr_site;
3434pt_property_site pt_exh_throw_expr_site;
3535
36- /* the `Error` class name of the twin's `new ObjectType(Error::class)`, a
37- * permanent interned string (module startup) */
38- zend_string *pt_exh_error_class_name = nullptr ;
39-
4036/* $stmt->expr of the Expression statement (NULL = pending exception) */
4137zval *statementExpr (zval *stmt)
4238{
@@ -124,15 +120,12 @@ class ExpressionHandler
124120
125121 if (UNEXPECTED (!pt_node_scope_resolver_call_node_callback (nodeScopeResolver, nodeCallback, stmt, stmtScope, storage))) return zv::Val ();
126122
127- // Errors signal programmer mistakes (ValueError, TypeError, DivisionByZeroError...),
128- // nobody calls an otherwise pure expression just to have them thrown, so they
129- // do not make the expression statement meaningful.
130123 zval *resultValue = result.raw ();
131124 zv::Val throwPointsHold;
132125 zval *throwPoints = pt_expression_result_throw_points (resultValue, throwPointsHold);
133126 if (UNEXPECTED (throwPoints == NULL )) return zv::Val ();
134- uint32_t meaningfulThrowPoints = 0 ;
135- if (UNEXPECTED (!countMeaningfulThrowPoints (throwPoints, meaningfulThrowPoints ))) return zv::Val ();
127+ uint32_t explicitThrowPoints = 0 ;
128+ if (UNEXPECTED (!countExplicitThrowPoints (throwPoints, explicitThrowPoints ))) return zv::Val ();
136129
137130 zv::Val impurePointsHold;
138131 zval *impurePoints = pt_expression_result_impure_points (resultValue, impurePointsHold);
@@ -141,7 +134,7 @@ class ExpressionHandler
141134 zend_type_error (" count(): Argument #1 ($value) must be of type Countable|array, %s given" , zend_zval_value_name (impurePoints));
142135 return zv::Val ();
143136 }
144- if (zend_hash_num_elements (Z_ARRVAL_P (impurePoints)) == 0 && meaningfulThrowPoints == 0 ) {
137+ if (zend_hash_num_elements (Z_ARRVAL_P (impurePoints)) == 0 && explicitThrowPoints == 0 ) {
145138 expr = statementExpr (stmt);
146139 if (UNEXPECTED (expr == NULL )) return zv::Val ();
147140 bool incDec = ptsh::isInstanceOf (expr, PT_CLASS_POST_INC , error)
@@ -263,17 +256,14 @@ class ExpressionHandler
263256 return pt_expression_result_with_scope (result.raw (), constrainedScope.raw ());
264257 }
265258
266- /* count(array_filter($throwPoints, static fn ($throwPoint) =>
267- * $throwPoint->isExplicit() && !$errorType->isSuperTypeOf($throwPoint->getType())->yes())),
268- * with the twin's `new ObjectType(Error::class)` created on the first
269- * explicit throw point; false = pending exception */
270- [[nodiscard]] static bool countMeaningfulThrowPoints (zval *throwPoints, uint32_t &count)
259+ /* count(array_filter($throwPoints, static fn ($throwPoint) => $throwPoint->isExplicit()));
260+ * false = pending exception */
261+ [[nodiscard]] static bool countExplicitThrowPoints (zval *throwPoints, uint32_t &count)
271262 {
272263 if (UNEXPECTED (Z_TYPE_P (throwPoints) != IS_ARRAY )) {
273264 zend_type_error (" array_filter(): Argument #1 ($array) must be of type array, %s given" , zend_zval_value_name (throwPoints));
274265 return false ;
275266 }
276- zv::Val errorType;
277267 for (auto entry : zv::TableRef (Z_ARRVAL_P (throwPoints))) {
278268 zval *throwPoint = entry.value ().deref ().raw ();
279269 if (UNEXPECTED (Z_TYPE_P (throwPoint) != IS_OBJECT )) {
@@ -282,30 +272,7 @@ class ExpressionHandler
282272 }
283273 bool isExplicit;
284274 if (UNEXPECTED (!pt_internal_throw_point_is_explicit (throwPoint, isExplicit))) return false ;
285- if (!isExplicit) continue ;
286- bool fromThrowExpr;
287- if (UNEXPECTED (!pt_internal_throw_point_is_from_throw_expr (throwPoint, fromThrowExpr))) return false ;
288- if (fromThrowExpr) {
289- count++;
290- continue ;
291- }
292- if (errorType.isUndef ()) {
293- zval errorTypeValue;
294- if (UNEXPECTED (!pt_object_type_new (&errorTypeValue, pt_exh_error_class_name))) return false ;
295- errorType = zv::Val::adopt (errorTypeValue);
296- }
297- zv::Val typeHold;
298- zval *type = pt_internal_throw_point_type (throwPoint, typeHold);
299- if (UNEXPECTED (type == NULL )) return false ;
300- zv::Val isSuperType = pt_type_op (Z_OBJ_P (errorType.raw ()), PT_OP_IS_SUPER_TYPE_OF , 1 , type);
301- if (UNEXPECTED (isSuperType.isUndef ())) return false ;
302- if (UNEXPECTED (Z_TYPE_P (isSuperType.raw ()) != IS_OBJECT )) {
303- memberCallOnNonObject (" yes" , isSuperType.raw ());
304- return false ;
305- }
306- zend_long value = pt_result_value (Z_OBJ_P (isSuperType.raw ()));
307- if (UNEXPECTED (value < 0 )) return false ;
308- if (value != PT_TRI_YES ) {
275+ if (isExplicit) {
309276 count++;
310277 }
311278 }
@@ -357,8 +324,6 @@ using phpstanturbo::ExpressionHandler;
357324
358325void pt_register_expression_handler ()
359326{
360- pt_exh_error_class_name = zend_string_init_interned (PT_LC (" Error" ), 1 );
361-
362327 reg::Class cls (" PHPStan\\ Analyser\\ StmtHandler\\ ExpressionHandler" );
363328 ptdecl::ExpressionHandler::declareClass (cls);
364329 ptdecl::ExpressionHandler::declareProperties (cls);
0 commit comments