Skip to content

Commit 6e24c16

Browse files
committed
add compatibility for tentative-return-type
1 parent 5365e1d commit 6e24c16

File tree

4 files changed

+42
-8
lines changed

4 files changed

+42
-8
lines changed

build/gen_stub.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3769,12 +3769,16 @@ protected function pName_FullyQualified(Name\FullyQualified $node) {
37693769
return $fileInfo;
37703770
}
37713771

3772-
function funcInfoToCode(FuncInfo $funcInfo): string {
3772+
function funcInfoToCode(FileInfo $fileInfo, FuncInfo $funcInfo): string {
37733773
$code = '';
37743774
$returnType = $funcInfo->return->type;
37753775
$isTentativeReturnType = $funcInfo->return->tentativeReturnType;
3776+
$php81MinimumCompatibility = $fileInfo->generateLegacyArginfoForPhpVersionId === null || $fileInfo->generateLegacyArginfoForPhpVersionId >= PHP_81_VERSION_ID;
37763777

37773778
if ($returnType !== null) {
3779+
if ($isTentativeReturnType && !$php81MinimumCompatibility) {
3780+
$code .= "#if (PHP_VERSION_ID >= " . PHP_81_VERSION_ID . ")\n";
3781+
}
37783782
if (null !== $simpleReturnType = $returnType->tryToSimpleType()) {
37793783
if ($simpleReturnType->isBuiltin) {
37803784
$code .= sprintf(
@@ -3813,6 +3817,12 @@ function funcInfoToCode(FuncInfo $funcInfo): string {
38133817
);
38143818
}
38153819
}
3820+
if ($isTentativeReturnType && !$php81MinimumCompatibility) {
3821+
$code .= sprintf(
3822+
"#else\nZEND_BEGIN_ARG_INFO_EX(%s, 0, %d, %d)\n#endif\n",
3823+
$funcInfo->getArgInfoName(), $funcInfo->return->byRef, $funcInfo->numRequiredArgs
3824+
);
3825+
}
38163826
} else {
38173827
$code .= sprintf(
38183828
"ZEND_BEGIN_ARG_INFO_EX(%s, 0, %d, %d)\n",
@@ -3925,15 +3935,15 @@ function generateArgInfoCode(
39253935
$generatedFuncInfos = [];
39263936
$code .= generateCodeWithConditions(
39273937
$fileInfo->getAllFuncInfos(), "\n",
3928-
static function (FuncInfo $funcInfo) use (&$generatedFuncInfos) {
3938+
static function (FuncInfo $funcInfo) use (&$generatedFuncInfos, $fileInfo) {
39293939
/* If there already is an equivalent arginfo structure, only emit a #define */
39303940
if ($generatedFuncInfo = findEquivalentFuncInfo($generatedFuncInfos, $funcInfo)) {
39313941
$code = sprintf(
39323942
"#define %s %s\n",
39333943
$funcInfo->getArgInfoName(), $generatedFuncInfo->getArgInfoName()
39343944
);
39353945
} else {
3936-
$code = funcInfoToCode($funcInfo);
3946+
$code = funcInfoToCode($fileInfo, $funcInfo);
39373947
}
39383948

39393949
$generatedFuncInfos[] = $funcInfo;

ext/zend_test/test.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,8 @@ static ZEND_METHOD(_ZendTestTrait, testMethod)
531531
static ZEND_METHOD(ZendTestNS_Foo, method)
532532
{
533533
ZEND_PARSE_PARAMETERS_NONE();
534+
535+
RETURN_LONG(0);
534536
}
535537

536538
static ZEND_METHOD(ZendTestNS2_Foo, method)

ext/zend_test/test.stub.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
<?php
22

3-
/** @generate-class-entries static */
4-
3+
/**
4+
* @generate-class-entries static
5+
* @generate-legacy-arginfo 80000
6+
*/
57
namespace {
68

79
require "Zend/zend_attributes.stub.php";
@@ -137,7 +139,8 @@ function zend_test_zend_ini_parse_uquantity(string $str): int {}
137139
namespace ZendTestNS {
138140

139141
class Foo {
140-
public function method(): void {}
142+
/** @tentative-return-type */
143+
public function method(): int {}
141144
}
142145

143146
}

ext/zend_test/test_arginfo.h

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

0 commit comments

Comments
 (0)