Skip to content

Commit 65a77cd

Browse files
committed
Start of a working stub generation
1 parent fc3e75f commit 65a77cd

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

build/gen_stub.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,6 @@ public static function fromString(string $typeString): SimpleType
203203
case "float":
204204
case "string":
205205
case "callable":
206-
case "iterable":
207206
case "object":
208207
case "resource":
209208
case "mixed":
@@ -215,6 +214,8 @@ public static function fromString(string $typeString): SimpleType
215214
return ArrayType::createGenericArray();
216215
case "self":
217216
throw new Exception('The exact class name must be used instead of "self"');
217+
case "iterable":
218+
throw new Exception('This should not happen');
218219
}
219220

220221
$matches = [];
@@ -278,8 +279,6 @@ public function toTypeCode(): string {
278279
return "IS_VOID";
279280
case "callable":
280281
return "IS_CALLABLE";
281-
case "iterable":
282-
return "IS_ITERABLE";
283282
case "mixed":
284283
return "IS_MIXED";
285284
case "static":
@@ -313,8 +312,6 @@ public function toTypeMask(): string {
313312
return "MAY_BE_OBJECT";
314313
case "callable":
315314
return "MAY_BE_CALLABLE";
316-
case "iterable":
317-
return "MAY_BE_ITERABLE";
318315
case "mixed":
319316
return "MAY_BE_ANY";
320317
case "void":
@@ -421,12 +418,21 @@ public static function fromNode(Node $node): Type {
421418
if ($node instanceof Node\NullableType) {
422419
return new Type(
423420
[
424-
SimpleType::fromNode($node->type),
421+
...Type::fromNode($node->type)->types,
425422
SimpleType::null(),
426423
]
427424
);
428425
}
429426

427+
if ($node instanceof Node\Identifier && $node->toLowerString() === "iterable") {
428+
return new Type(
429+
[
430+
SimpleType::fromString("Traversable"),
431+
ArrayType::createGenericArray(),
432+
]
433+
);
434+
}
435+
430436
return new Type([SimpleType::fromNode($node)]);
431437
}
432438

ext/zend_test/test_arginfo.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_zend_string_or_stdclass_or_n
5353
ZEND_END_ARG_INFO()
5454

5555
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_zend_iterable, 0, 1, IS_VOID, 0)
56-
ZEND_ARG_TYPE_INFO(0, arg1, IS_ITERABLE, 0)
57-
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, arg2, IS_ITERABLE, 1, "null")
56+
ZEND_ARG_OBJ_TYPE_MASK(0, arg1, Traversable, MAY_BE_ARRAY, NULL)
57+
ZEND_ARG_OBJ_TYPE_MASK(0, arg2, Traversable, MAY_BE_ARRAY|MAY_BE_NULL, "null")
5858
ZEND_END_ARG_INFO()
5959

6060
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_zend_weakmap_attach, 0, 2, _IS_BOOL, 0)

0 commit comments

Comments
 (0)