Skip to content

Commit 3e961ab

Browse files
authored
Merge pull request #2383 from zephir-lang/development
0.16.2
2 parents 9c99b4c + 717b0ce commit 3e961ab

File tree

9 files changed

+83
-17
lines changed

9 files changed

+83
-17
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org).
66

77
## [Unreleased]
88

9+
## [0.16.2] - 2022-08-22
10+
### Added
11+
- Added support for `object` return type [#2374](https://github.com/zephir-lang/zephir/issues/2374)
12+
913
## [0.16.1] - 2022-08-21
1014
### Changed
1115
- Changed usage of `utf8_decode()` function in favour of `mb_convert_encoding()` [#2376](https://github.com/zephir-lang/zephir/issues/2376)
@@ -579,7 +583,8 @@ and this project adheres to [Semantic Versioning](https://semver.org).
579583
[#1524](https://github.com/zephir-lang/zephir/issues/1524)
580584

581585

582-
[Unreleased]: https://github.com/zephir-lang/zephir/compare/0.16.0...HEAD
586+
[Unreleased]: https://github.com/zephir-lang/zephir/compare/0.16.2...HEAD
587+
[0.16.2]: https://github.com/zephir-lang/zephir/compare/0.16.1...0.16.2
583588
[0.16.1]: https://github.com/zephir-lang/zephir/compare/0.16.0...0.16.1
584589
[0.16.0]: https://github.com/zephir-lang/zephir/compare/0.15.2...0.16.0
585590
[0.15.2]: https://github.com/zephir-lang/zephir/compare/0.15.1...0.15.2

Library/ArgInfoDefinition.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,33 @@ private function richRenderStart(): void
260260
return;
261261
}
262262

263+
if ($this->functionLike->isReturnTypeObject()) {
264+
$this->codePrinter->output('#if PHP_VERSION_ID >= 80000');
265+
$this->codePrinter->output(
266+
sprintf(
267+
'ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(%s, %d, %d, %s)',
268+
$this->name,
269+
(int) $this->returnByRef,
270+
$this->functionLike->getNumberOfRequiredParameters(),
271+
'MAY_BE_OBJECT',
272+
)
273+
);
274+
$this->codePrinter->output('#else');
275+
$this->codePrinter->output(
276+
sprintf(
277+
'ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(%s, %d, %d, %s, %d)',
278+
$this->name,
279+
(int) $this->returnByRef,
280+
$this->functionLike->getNumberOfRequiredParameters(),
281+
'IS_OBJECT',
282+
0,
283+
)
284+
);
285+
$this->codePrinter->output('#endif');
286+
287+
return;
288+
}
289+
263290
if (count($this->functionLike->getReturnTypes()) > 1) {
264291
$types = [];
265292
$mayBeTypes = $this->functionLike->getMayBeArgTypes();

Library/ClassMethod.php

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,11 @@ public function areReturnTypesStringCompatible(): bool
712712
return isset($this->returnTypes['string']);
713713
}
714714

715+
public function areReturnTypesObjectCompatible(): bool
716+
{
717+
return isset($this->returnTypes['object']);
718+
}
719+
715720
/**
716721
* Returned type hints by the method.
717722
*
@@ -2224,24 +2229,17 @@ public function hasChildReturnStatementType(array $statement): bool
22242229
}
22252230

22262231
$statements = $statement['else_statements'];
2227-
foreach ($statements as $item) {
2228-
$type = $item['type'] ?? null;
2229-
if ('return' === $type || 'throw' === $type) {
2230-
return true;
2231-
}
2232-
2233-
return $this->hasChildReturnStatementType($item);
2234-
}
22352232
} else {
22362233
$statements = $statement['statements'];
2237-
foreach ($statements as $item) {
2238-
$type = $item['type'] ?? null;
2239-
if ('return' === $type || 'throw' === $type) {
2240-
return true;
2241-
}
2234+
}
22422235

2243-
return $this->hasChildReturnStatementType($item);
2236+
foreach ($statements as $item) {
2237+
$type = $item['type'] ?? null;
2238+
if ('return' === $type || 'throw' === $type) {
2239+
return true;
22442240
}
2241+
2242+
return $this->hasChildReturnStatementType($item);
22452243
}
22462244

22472245
return false;
@@ -2323,6 +2321,7 @@ public function isReturnTypesHintDetermined(): bool
23232321
$this->areReturnTypesNullCompatible() ||
23242322
$this->areReturnTypesStringCompatible() ||
23252323
$this->areReturnTypesFalseCompatible() ||
2324+
$this->areReturnTypesObjectCompatible() ||
23262325
\array_key_exists('array', $this->getReturnTypes())
23272326
) {
23282327
continue;
@@ -2350,6 +2349,16 @@ public function isReturnTypeNullableObject(): bool
23502349
return count($this->returnTypes) === 2 && isset($this->returnTypes['object']) && isset($this->returnTypes['null']);
23512350
}
23522351

2352+
/**
2353+
* Checks if method's return type is object `object`.
2354+
*
2355+
* @return bool
2356+
*/
2357+
public function isReturnTypeObject(): bool
2358+
{
2359+
return count($this->returnTypes) === 1 && isset($this->returnTypes['object']);
2360+
}
2361+
23532362
/**
23542363
* Checks if the method have compatible return types.
23552364
*

Library/Zephir.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
final class Zephir
1717
{
18-
public const VERSION = '0.16.0-$Id$';
18+
public const VERSION = '0.16.2-$Id$';
1919

2020
public const LOGO = <<<'ASCII'
2121
_____ __ _

ext/php_stub.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#define PHP_STUB_VERSION "1.0.0"
1515
#define PHP_STUB_EXTNAME "stub"
1616
#define PHP_STUB_AUTHOR "Phalcon Team and contributors"
17-
#define PHP_STUB_ZEPVERSION "0.16.0-$Id$"
17+
#define PHP_STUB_ZEPVERSION "0.16.2-$Id$"
1818
#define PHP_STUB_DESCRIPTION "Description <b>test</b> for<br/>Test Extension."
1919

2020
typedef struct _zephir_struct_db {

ext/stub/types/obj.zep.c

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/stub/types/obj.zep.h

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

stub/types/obj.zep

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,9 @@ class Obj
1212
{
1313
return new \stdClass();
1414
}
15+
16+
public function objectReturn() -> object
17+
{
18+
return new \stdClass();
19+
}
1520
}

tests/Extension/Types/ObjTypeTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@ public function testIntFalse(): void
2525

2626
$this->assertNull($class->nullableObjectReturnNull());
2727
$this->assertInstanceOf(stdClass::class, $class->nullableObjectReturnObj());
28+
$this->assertInstanceOf(stdClass::class, $class->objectReturn());
2829
}
2930
}

0 commit comments

Comments
 (0)