Skip to content

Commit 36b86e7

Browse files
committed
adds a method to test union type arginfo registration
1 parent 92284c7 commit 36b86e7

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

ext/zend_test/test.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -884,6 +884,28 @@ static void le_throwing_resource_dtor(zend_resource *rsrc)
884884
zend_throw_exception(NULL, "Throwing resource destructor called", 0);
885885
}
886886

887+
static ZEND_METHOD(_ZendTestClass, takesUnionType)
888+
{
889+
zend_object *obj;
890+
ZEND_PARSE_PARAMETERS_START(1, 1);
891+
Z_PARAM_OBJ(obj)
892+
ZEND_PARSE_PARAMETERS_END();
893+
// we have to perform type-checking to avoid arginfo/zpp mismatch error,
894+
bool type_matches = (
895+
instanceof_function(obj->ce, zend_standard_class_def)
896+
||
897+
instanceof_function(obj->ce, zend_ce_iterator)
898+
);
899+
if (!type_matches) {
900+
zend_string *ty = zend_type_to_string(execute_data->func->internal_function.arg_info->type);
901+
zend_argument_type_error(1, "must be of type %s, %s given", ty->val, obj->ce->name->val);
902+
zend_string_release(ty);
903+
RETURN_THROWS();
904+
}
905+
906+
RETURN_NULL();
907+
}
908+
887909
// Returns a newly allocated DNF type `Iterator|(Traversable&Countable)`.
888910
//
889911
// We need to generate it "manually" because gen_stubs.php does not support codegen for DNF types ATM.
@@ -938,6 +960,7 @@ static ZEND_NAMED_FUNCTION(zend_test_internal_dnf_arguments)
938960
zend_string *ty = zend_type_to_string(arginfo_zend_test_internal_dnf_arguments[1].type);
939961
zend_argument_type_error(1, "must be of type %s, %s given", ty->val, obj->ce->name->val);
940962
zend_string_release(ty);
963+
RETURN_THROWS();
941964
}
942965

943966
RETURN_OBJ_COPY(obj);

ext/zend_test/test.stub.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ public function returnsStatic(): static {}
5353
public function returnsThrowable(): Throwable {}
5454

5555
static public function variadicTest(string|Iterator ...$elements) : static {}
56+
57+
public function takesUnionType(stdclass|Iterator $arg): void {}
5658
}
5759

5860
class _ZendTestChildClass extends _ZendTestClass

ext/zend_test/test_arginfo.h

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)