Skip to content

Commit 0234409

Browse files
committed
Start of a working stub generation
1 parent eb6aa08 commit 0234409

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":
@@ -317,8 +316,6 @@ public function toTypeMask(): string {
317316
return "MAY_BE_OBJECT";
318317
case "callable":
319318
return "MAY_BE_CALLABLE";
320-
case "iterable":
321-
return "MAY_BE_ITERABLE";
322319
case "mixed":
323320
return "MAY_BE_ANY";
324321
case "void":
@@ -424,12 +421,21 @@ public static function fromNode(Node $node): Type {
424421
if ($node instanceof Node\NullableType) {
425422
return new Type(
426423
[
427-
SimpleType::fromNode($node->type),
424+
...Type::fromNode($node->type)->types,
428425
SimpleType::null(),
429426
]
430427
);
431428
}
432429

430+
if ($node instanceof Node\Identifier && $node->toLowerString() === "iterable") {
431+
return new Type(
432+
[
433+
SimpleType::fromString("Traversable"),
434+
ArrayType::createGenericArray(),
435+
]
436+
);
437+
}
438+
433439
return new Type([SimpleType::fromNode($node)]);
434440
}
435441

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)