Skip to content

Commit 9f55e69

Browse files
ondrejmirtesclaude
andcommitted
Raise the twins' TypeErrors for non-Type values crossing into the natives
The natives accepted a non-Type object where the twins declare a Type: the constructor glue of the Type classes and every equals() parsed a `Type` / `?Type` parameter with Z_PARAM_OBJECT (StringType::equals() answered false for a stdClass, new IterableType(new stdClass, ...) built an object that failed later with an Error), and traverse callbacks returning a non-Type object passed through CallableType, ClosureType, GenericObjectType, GenericStaticType, UnionType, BenevolentUnionType, IntersectionType and pt_type_traverse_call(). A method missing on a non-Type receiver raised "phpstan_turbo: method X::y not found" instead of the engine's "Call to undefined method X::y()". The zp::TypeObj / zp::TypeObjOrNull parameter kinds check the argument against the Type interface (the TemplateType constructors' $default too); pt_call_type_fci() checks a traverse callback's result — only for callables that are not native, the native ones return Types — where the twin hands it on to a Type parameter; pt_throw_undefined_method() raises the engine's Error with the method spelled as the Type interface declares it. CombinationsHelper's array-of-arrays TypeError names the declared class instead of PHPStanTurbo\CombinationsHelper. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018Fdg8n3eEi4ZoXa4dA2k4A
1 parent eef8715 commit 9f55e69

58 files changed

Lines changed: 230 additions & 105 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎turbo-ext/src/AbsorbedTemplateArgumentType.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ void pt_register_absorbed_template_argument_type()
4848

4949
cls.method(sigs::equals, [](INTERNAL_FUNCTION_PARAMETERS) {
5050
zval *type;
51-
if (!zp::parse<zp::Obj>(execute_data, type)) RETURN_THROWS();
51+
if (!zp::parse<zp::TypeObj>(execute_data, type)) RETURN_THROWS();
5252
RETURN_BOOL(AbsorbedTemplateArgumentType::equals(type));
5353
});
5454

‎turbo-ext/src/AccessoryArrayListType.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ void pt_register_accessory_array_list_type()
397397

398398
cls.method(sigs::equals, [](INTERNAL_FUNCTION_PARAMETERS) {
399399
zval *type;
400-
if (!zp::parse<zp::Obj>(execute_data, type)) RETURN_THROWS();
400+
if (!zp::parse<zp::TypeObj>(execute_data, type)) RETURN_THROWS();
401401
RETURN_BOOL(AccessoryArrayListType::equals(type));
402402
});
403403
cls.op(PT_OP_EQUALS, PT_OP_LAMBDA { return zv::Val::boolean(AccessoryArrayListType::equals(argv)); });

‎turbo-ext/src/AccessoryDecimalIntegerStringType.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ void pt_register_accessory_decimal_integer_string_type()
592592
PT_RETURN_VAL(PT_THIS.isAcceptedBy(acceptingType));
593593
});
594594

595-
cls.method<&AccessoryDecimalIntegerStringType::equals, zp::Obj>(sigs::equals);
595+
cls.method<&AccessoryDecimalIntegerStringType::equals, zp::TypeObj>(sigs::equals);
596596
cls.op<PT_OP_EQUALS, &AccessoryDecimalIntegerStringType::equals>();
597597

598598
cls.method(sigs::describe, [](INTERNAL_FUNCTION_PARAMETERS) {

‎turbo-ext/src/AccessoryLiteralStringType.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ void pt_register_accessory_literal_string_type()
342342

343343
cls.method(sigs::equals, [](INTERNAL_FUNCTION_PARAMETERS) {
344344
zval *type;
345-
if (!zp::parse<zp::Obj>(execute_data, type)) RETURN_THROWS();
345+
if (!zp::parse<zp::TypeObj>(execute_data, type)) RETURN_THROWS();
346346
RETURN_BOOL(AccessoryLiteralStringType::equals(type));
347347
});
348348
cls.op(PT_OP_EQUALS, PT_OP_LAMBDA { return zv::Val::boolean(AccessoryLiteralStringType::equals(argv)); });

‎turbo-ext/src/AccessoryLowercaseStringType.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ void pt_register_accessory_lowercase_string_type()
369369

370370
cls.method(sigs::equals, [](INTERNAL_FUNCTION_PARAMETERS) {
371371
zval *type;
372-
if (!zp::parse<zp::Obj>(execute_data, type)) RETURN_THROWS();
372+
if (!zp::parse<zp::TypeObj>(execute_data, type)) RETURN_THROWS();
373373
RETURN_BOOL(AccessoryLowercaseStringType::equals(type));
374374
});
375375
cls.op(PT_OP_EQUALS, PT_OP_LAMBDA { return zv::Val::boolean(AccessoryLowercaseStringType::equals(argv)); });

‎turbo-ext/src/AccessoryNonEmptyStringType.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ void pt_register_accessory_non_empty_string_type()
367367

368368
cls.method(sigs::equals, [](INTERNAL_FUNCTION_PARAMETERS) {
369369
zval *type;
370-
if (!zp::parse<zp::Obj>(execute_data, type)) RETURN_THROWS();
370+
if (!zp::parse<zp::TypeObj>(execute_data, type)) RETURN_THROWS();
371371
RETURN_BOOL(AccessoryNonEmptyStringType::equals(type));
372372
});
373373
cls.op(PT_OP_EQUALS, PT_OP_LAMBDA { return zv::Val::boolean(AccessoryNonEmptyStringType::equals(argv)); });

‎turbo-ext/src/AccessoryNonFalsyStringType.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ void pt_register_accessory_non_falsy_string_type()
364364

365365
cls.method(sigs::equals, [](INTERNAL_FUNCTION_PARAMETERS) {
366366
zval *type;
367-
if (!zp::parse<zp::Obj>(execute_data, type)) RETURN_THROWS();
367+
if (!zp::parse<zp::TypeObj>(execute_data, type)) RETURN_THROWS();
368368
RETURN_BOOL(AccessoryNonFalsyStringType::equals(type));
369369
});
370370
cls.op(PT_OP_EQUALS, PT_OP_LAMBDA { return zv::Val::boolean(AccessoryNonFalsyStringType::equals(argv)); });

‎turbo-ext/src/AccessoryNumericStringType.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ void pt_register_accessory_numeric_string_type()
416416

417417
cls.method(sigs::equals, [](INTERNAL_FUNCTION_PARAMETERS) {
418418
zval *type;
419-
if (!zp::parse<zp::Obj>(execute_data, type)) RETURN_THROWS();
419+
if (!zp::parse<zp::TypeObj>(execute_data, type)) RETURN_THROWS();
420420
RETURN_BOOL(AccessoryNumericStringType::equals(type));
421421
});
422422
cls.op(PT_OP_EQUALS, PT_OP_LAMBDA { return zv::Val::boolean(AccessoryNumericStringType::equals(argv)); });

‎turbo-ext/src/AccessoryUppercaseStringType.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ void pt_register_accessory_uppercase_string_type()
369369

370370
cls.method(sigs::equals, [](INTERNAL_FUNCTION_PARAMETERS) {
371371
zval *type;
372-
if (!zp::parse<zp::Obj>(execute_data, type)) RETURN_THROWS();
372+
if (!zp::parse<zp::TypeObj>(execute_data, type)) RETURN_THROWS();
373373
RETURN_BOOL(AccessoryUppercaseStringType::equals(type));
374374
});
375375
cls.op(PT_OP_EQUALS, PT_OP_LAMBDA { return zv::Val::boolean(AccessoryUppercaseStringType::equals(argv)); });

‎turbo-ext/src/ArrayType.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2070,7 +2070,7 @@ void pt_register_array_type()
20702070

20712071
cls.method(sigs::__construct, [](INTERNAL_FUNCTION_PARAMETERS) {
20722072
zval *keyType, *itemType;
2073-
if (!zp::parse<zp::Obj, zp::Obj>(execute_data, keyType, itemType)) RETURN_THROWS();
2073+
if (!zp::parse<zp::TypeObj, zp::TypeObj>(execute_data, keyType, itemType)) RETURN_THROWS();
20742074
if (UNEXPECTED(!ArrayType::checkType(keyType, "__construct", 1, "keyType") || !ArrayType::checkType(itemType, "__construct", 2, "itemType"))) {
20752075
RETURN_THROWS();
20762076
}
@@ -2103,7 +2103,7 @@ void pt_register_array_type()
21032103
cls.method<&ArrayType::isSuperTypeOf, zp::Obj>(sigs::isSuperTypeOf);
21042104
cls.op<PT_OP_IS_SUPER_TYPE_OF, &ArrayType::isSuperTypeOf>();
21052105

2106-
cls.method<&ArrayType::equals, zp::Obj>(sigs::equals);
2106+
cls.method<&ArrayType::equals, zp::TypeObj>(sigs::equals);
21072107
cls.op<PT_OP_EQUALS, &ArrayType::equals>();
21082108

21092109
cls.method<&ArrayType::describe, zp::Obj>(sigs::describe);

0 commit comments

Comments
 (0)