summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2021-03-18 17:11:56 +0100
committerNikita Popov <nikita.ppv@gmail.com>2021-03-18 17:11:56 +0100
commitdcac654fd56a2cecec0c187ba061ecc82bbc9031 (patch)
tree57fd146f6a4deb209c0ebae32341066cf0cd7836 /ext
parent2f73cbb1b10f197674f4adb15f39a1d2d1aa4824 (diff)
downloadphp-git-dcac654fd56a2cecec0c187ba061ecc82bbc9031.tar.gz
Allow inferring narrowed return type
Even if an explicit return type is given, we might still infer a more narrow one based on return statements. We shouldn't pessimize this just because a type has been declared.
Diffstat (limited to 'ext')
-rw-r--r--ext/opcache/tests/opt/verify_return_type.phpt44
1 files changed, 44 insertions, 0 deletions
diff --git a/ext/opcache/tests/opt/verify_return_type.phpt b/ext/opcache/tests/opt/verify_return_type.phpt
new file mode 100644
index 0000000000..c1384c7af8
--- /dev/null
+++ b/ext/opcache/tests/opt/verify_return_type.phpt
@@ -0,0 +1,44 @@
+--TEST--
+Return type check elision
+--INI--
+opcache.enable=1
+opcache.enable_cli=1
+opcache.optimization_level=-1
+opcache.opt_debug_level=0x20000
+opcache.preload=
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+
+class Test1 {
+ final public function getIntOrFloat(int $i): int|float {
+ return $i;
+ }
+ final public function getInt(): int {
+ return $this->getIntOrFloat();
+ }
+}
+
+?>
+--EXPECTF--
+$_main:
+ ; (lines=1, args=0, vars=0, tmps=0)
+ ; (after optimizer)
+ ; %s
+0000 RETURN int(1)
+
+Test1::getIntOrFloat:
+ ; (lines=2, args=1, vars=1, tmps=0)
+ ; (after optimizer)
+ ; %s
+0000 CV0($i) = RECV 1
+0001 RETURN CV0($i)
+
+Test1::getInt:
+ ; (lines=3, args=0, vars=0, tmps=1)
+ ; (after optimizer)
+ ; %s
+0000 INIT_METHOD_CALL 0 THIS string("getIntOrFloat")
+0001 V0 = DO_UCALL
+0002 RETURN V0