Skip to content

Commit b13d051

Browse files
phpstan-botclaude
authored andcommitted
Revert the lazy verbosity in ObjectShapeType::accepts()
It is not needed for big array shapes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 8435521 commit b13d051

3 files changed

Lines changed: 10 additions & 26 deletions

File tree

‎src/Type/ObjectShapeType.php‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -244,13 +244,8 @@ public function accepts(Type $type, bool $strictTypes): AcceptsResult
244244
}
245245

246246
$otherPropertyType = $otherProperty->getReadableType();
247-
$acceptsValue = $propertyType->accepts($otherPropertyType, $strictTypes);
248-
if ($acceptsValue->yes() && count($acceptsValue->reasons) === 0) {
249-
continue;
250-
}
251-
252247
$verbosity = VerbosityLevel::getRecommendedLevelByType($propertyType, $otherPropertyType);
253-
$acceptsValue = $acceptsValue->decorateReasons(
248+
$acceptsValue = $propertyType->accepts($otherPropertyType, $strictTypes)->decorateReasons(
254249
static fn (string $reason) => sprintf(
255250
'Property ($%s) type %s does not accept type %s: %s',
256251
$propertyName,

‎turbo-ext/src/ObjectShapeType.cpp‎

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -246,24 +246,6 @@ class ObjectShapeType
246246

247247
zv::Val otherPropertyType = pt_type_call(Z_OBJ_P(otherProperty.raw()), PT_LC("getreadabletype"), 0, NULL);
248248
if (UNEXPECTED(otherPropertyType.isUndef())) return zv::Val();
249-
/* $acceptsValue = $propertyType->accepts($otherPropertyType, $strictTypes) */
250-
zend_object *propertyTypeObj = propertyTypeObject(propertyType, "accepts");
251-
if (UNEXPECTED(propertyTypeObj == NULL)) return zv::Val();
252-
zv::Args acceptsArgs{otherPropertyType.raw(), strictTypes};
253-
zv::Val acceptsValue = pt_type_op(propertyTypeObj, PT_OP_ACCEPTS, 2, acceptsArgs);
254-
if (UNEXPECTED(acceptsValue.isUndef())) return zv::Val();
255-
if (UNEXPECTED(!zv::Ref(acceptsValue.raw()).isObject())) {
256-
zend_type_error("phpstan_turbo: accepts() must return %s", ZSTR_VAL(pt_ce_accepts_result->name));
257-
return zv::Val();
258-
}
259-
/* $acceptsValue->yes() && count($acceptsValue->reasons) === 0: continue */
260-
zend_long acceptsValueBefore = pt_type_result_trinary(acceptsValue.raw());
261-
if (UNEXPECTED(acceptsValueBefore < 0)) return zv::Val();
262-
if (acceptsValueBefore == PT_TRI_YES) {
263-
bool noReasonsBefore;
264-
if (UNEXPECTED(!hasNoReasons(acceptsValue.raw(), noReasonsBefore))) return zv::Val();
265-
if (noReasonsBefore) continue;
266-
}
267249
/* $verbosity = VerbosityLevel::getRecommendedLevelByType($propertyType, $otherPropertyType),
268250
* whose `Type $acceptingType` parameter is the first to see the property type */
269251
bool propertyIsType;
@@ -274,7 +256,14 @@ class ObjectShapeType
274256
}
275257
zv::Val verbosity = pt_type_verbosity_recommended(propertyType, otherPropertyType.raw());
276258
if (UNEXPECTED(verbosity.isUndef())) return zv::Val();
277-
/* ->decorateReasons(...) */
259+
/* $propertyType->accepts($otherPropertyType, $strictTypes)->decorateReasons(...) */
260+
zv::Args acceptsArgs{otherPropertyType.raw(), strictTypes};
261+
zv::Val acceptsValue = pt_type_op(Z_OBJ_P(propertyType), PT_OP_ACCEPTS, 2, acceptsArgs);
262+
if (UNEXPECTED(acceptsValue.isUndef())) return zv::Val();
263+
if (UNEXPECTED(!zv::Ref(acceptsValue.raw()).isObject())) {
264+
zend_type_error("phpstan_turbo: accepts() must return %s", ZSTR_VAL(pt_ce_accepts_result->name));
265+
return zv::Val();
266+
}
278267
zv::Val decorator = reasonDecorator(&propertyName, propertyType, otherPropertyType.raw(), verbosity.raw());
279268
acceptsValue = pt_type_call(Z_OBJ_P(acceptsValue.raw()), PT_LC("decoratereasons"), 1, decorator.raw());
280269
if (UNEXPECTED(acceptsValue.isUndef())) return zv::Val();

‎turbo-ext/tests/type-family.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8423,7 +8423,7 @@ public function getResolvedPhpDoc(): ?\PHPStan\PhpDoc\ResolvedPhpDocBlock { retu
84238423
] as $method => $call) {
84248424
$r["objectShape $valueName $method"] = $misuse($call, $withMessage);
84258425
}
8426-
// the accepts() call on the property type sees it first
8426+
// VerbosityLevel::getRecommendedLevelByType()'s typed parameter sees it first
84278427
$r["objectShape $valueName accepts"] = $misuse(static fn () => $badShape->accepts($misuseGoodShape, true));
84288428
$r["objectShape traverse returning $valueName describe"] = $misuse(static fn () => $misuseGoodShape->traverse(static fn () => $value)->describe(\PHPStan\Type\VerbosityLevel::precise()), $withMessage);
84298429
}

0 commit comments

Comments
 (0)