Skip to content

Commit

Permalink
Merge pull request #1910 from organization/development
Browse files Browse the repository at this point in the history
Fix #1908
  • Loading branch information
sergeyklay authored Sep 6, 2019
2 parents 1a6d6ea + 160ff14 commit d9107b6
Show file tree
Hide file tree
Showing 15 changed files with 262 additions and 16 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Fixed
- Fixed concatenation support of strings with double numbers
[#1893](https://github.com/phalcon/zephir/issues/1893)
- Fixed 'void' return type hint being ignored
[#1908](https://github.com/phalcon/zephir/issues/1908)

## [0.12.2] - 2019-08-05
### Added
Expand Down
65 changes: 64 additions & 1 deletion Library/ArgInfoDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function render()
) {
$this->richRenderStart();

if (false == $this->hasParameters()) {
if (false == $this->hasParameters() && false == $this->functionLike->isVoid()) {
$this->codePrinter->output('ZEND_END_ARG_INFO()');
$this->codePrinter->outputBlankLine();
}
Expand Down Expand Up @@ -156,6 +156,65 @@ private function richRenderStart()
return;
}

if ($this->functionLike->isVoid()) {
$this->codePrinter->output('#if PHP_VERSION_ID >= 70100');
$this->codePrinter->output('#if PHP_VERSION_ID >= 70200');
$this->codePrinter->output(
sprintf(
'ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(%s, %d, %d, %s, %d)',
$this->name,
(int) $this->returnByRef,
$this->functionLike->getNumberOfRequiredParameters(),
$this->getReturnType(),
(int) $this->functionLike->areReturnTypesNullCompatible()
)
);

$this->codePrinter->output('#else');

$this->codePrinter->output(
sprintf(
'ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(%s, %d, %d, %s, NULL, %d)',
$this->name,
(int) $this->returnByRef,
$this->functionLike->getNumberOfRequiredParameters(),
$this->getReturnType(),
(int) $this->functionLike->areReturnTypesNullCompatible()
)
);

$this->codePrinter->output('#endif');

if (false == $this->hasParameters()) {
$this->codePrinter->output('ZEND_END_ARG_INFO()');
}

$this->codePrinter->output('#else');

if (true == $this->hasParameters()) {
$this->codePrinter->output(
sprintf(
'ZEND_BEGIN_ARG_INFO_EX(%s, 0, %d, %d)',
$this->name,
(int) $this->returnByRef,
$this->functionLike->getNumberOfRequiredParameters()
)
);
}

$this->codePrinter->output(
sprintf(
'#define %s NULL',
$this->name
)
);

$this->codePrinter->output('#endif');
$this->codePrinter->outputBlankLine();

return;
}

$this->codePrinter->output('#if PHP_VERSION_ID >= 70200');
$this->codePrinter->output(
sprintf(
Expand Down Expand Up @@ -357,6 +416,10 @@ private function getReturnType()
return 'IS_STRING';
}

if ($this->functionLike->isVoid()) {
return 'IS_VOID';
}

if (\array_key_exists('array', $this->functionLike->getReturnTypes())) {
return 'IS_ARRAY';
}
Expand Down
12 changes: 10 additions & 2 deletions Library/ClassMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -2322,7 +2322,7 @@ public function getArgInfoName(ClassDefinition $classDefinition = null)
*
* Examples:
*
* - FALSE: function foo() -> void;
* - TRUE: function foo() -> void;
* - TRUE: function foo() -> null;
* - TRUE: function foo() -> bool|string|..;
* - TRUE: function foo() -> <\stdClass>;
Expand All @@ -2334,7 +2334,10 @@ public function getArgInfoName(ClassDefinition $classDefinition = null)
*/
public function isReturnTypesHintDetermined()
{
if (0 == \count($this->returnTypes) || $this->isVoid()) {
if ($this->isVoid()) {
return true;
}
if (0 == \count($this->returnTypes)) {
return false;
}

Expand Down Expand Up @@ -2376,6 +2379,11 @@ public function isReturnTypesHintDetermined()
*/
public function areReturnTypesCompatible()
{
// void
if ($this->isVoid()) {
return true;
}

// null | T1 | T2
if (\count($this->returnTypes) > 2) {
return false;
Expand Down
9 changes: 8 additions & 1 deletion Library/Stubs/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,16 @@ protected function buildMethod(ClassMethod $method, $isInterface, $indent)
}

$return = '';
if (version_compare(PHP_VERSION, '7.0.0', '>=') && $method->hasReturnTypes()) {
if (version_compare(PHP_VERSION, '7.0.0', '>=') && ($method->hasReturnTypes() || $method->isVoid())) {
$supported = 0;

if ($method->isVoid()) {
if (version_compare(PHP_VERSION, '7.1.0', '>=')) {
$return = 'void';
++$supported;
}
}

if (\array_key_exists('object', $method->getReturnTypes()) && 1 == \count($method->getReturnClassTypes())) {
$return = key($method->getReturnClassTypes());
++$supported;
Expand Down
41 changes: 33 additions & 8 deletions ext/install
Original file line number Diff line number Diff line change
@@ -1,20 +1,45 @@
#!/usr/bin/env bash
#
# This file was generated automatically by Zephir.
# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
#
# (c) Zephir Team <[email protected]>
#
# For the full copyright and license information, please view
# the LICENSE file that was distributed with this source code.

export CC="gcc"
export CFLAGS="-O2 -Wall -fvisibility=hidden -flto -DZEPHIR_RELEASE=1"

phpize_bin=$(which phpize 2> /dev/null)
IN_DOCKER=0

if [ -z $(which sudo 2> /dev/null) ]; then
alias sudo=""
if [[ -f /proc/1/cgroup ]]
then
if [[ -f /.dockerenv ]] || grep -Eq '/(lxc|docker)/[[:xdigit:]]{64}' /proc/1/cgroup
then
IN_DOCKER=1
fi
fi

phpize="$(command -v phpize 2> /dev/null)"

sudo=""
test "$IN_DOCKER" -eq 0 && sudo="$(command -v sudo 2> /dev/null)"

if [ -f Makefile ]; then
sudo make -s clean
sudo ${phpize_bin} --silent --clean
$sudo make -s clean
$sudo "${phpize}" --silent --clean
fi

${phpize_bin} --silent
${phpize} --silent

ZEPHIR_CFLAGS=""
ZEPHIR_LDFLAGS=""

test -n "$CFLAGS" && ZEPHIR_CFLAGS="CFLAGS=\"$CFLAGS\""
test -n "$LDFLAGS" && ZEPHIR_LDFLAGS="LDFLAGS=\"$LDFLAGS\""

/configure --silent --enable-test "$ZEPHIR_CFLAGS" "$ZEPHIR_LDFLAGS"

./configure --silent --enable-test
make -s && sudo make -s install
make -s
$sudo make -s install
2 changes: 1 addition & 1 deletion ext/php_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#define PHP_TEST_VERSION "1.0.0"
#define PHP_TEST_EXTNAME "test"
#define PHP_TEST_AUTHOR "Zephir Team and contributors"
#define PHP_TEST_ZEPVERSION "0.12.2-$Id$"
#define PHP_TEST_ZEPVERSION "0.12.3-$Id$"
#define PHP_TEST_DESCRIPTION "Description <b>test</b> for<br/>Test Extension."

typedef struct _zephir_struct_db {
Expand Down
13 changes: 12 additions & 1 deletion ext/test/bench/foo.zep.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions ext/test/concat.zep.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions ext/test/exitdie.zep.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 12 additions & 1 deletion ext/test/fortytwo.zep.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions ext/test/geometry.zep.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d9107b6

Please sign in to comment.