summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2019-09-19 17:20:10 +0200
committerNikita Popov <nikita.ppv@gmail.com>2019-09-19 17:21:00 +0200
commit003c13d7bc26aa2775041ffec955069802c86cf4 (patch)
treebebd48464f604578c03492524a23fcd89f35d1db
parent3e139a465333d3b2bed4d23e42316ea952d96dd8 (diff)
downloadphp-git-003c13d7bc26aa2775041ffec955069802c86cf4.tar.gz
Fix iterable return type optimization
-rw-r--r--ext/opcache/Optimizer/dfa_pass.c3
-rw-r--r--ext/opcache/tests/iterable_type_optimization.phpt17
2 files changed, 19 insertions, 1 deletions
diff --git a/ext/opcache/Optimizer/dfa_pass.c b/ext/opcache/Optimizer/dfa_pass.c
index c42b6d9856..f211306228 100644
--- a/ext/opcache/Optimizer/dfa_pass.c
+++ b/ext/opcache/Optimizer/dfa_pass.c
@@ -302,7 +302,8 @@ static inline zend_bool can_elide_return_type_check(
return 0;
}
- if (ZEND_TYPE_CODE(info->type) == IS_CALLABLE) {
+ /* These types are not represented exactly */
+ if (ZEND_TYPE_CODE(info->type) == IS_CALLABLE || ZEND_TYPE_CODE(info->type) == IS_ITERABLE) {
return 0;
}
diff --git a/ext/opcache/tests/iterable_type_optimization.phpt b/ext/opcache/tests/iterable_type_optimization.phpt
new file mode 100644
index 0000000000..b5247cd69c
--- /dev/null
+++ b/ext/opcache/tests/iterable_type_optimization.phpt
@@ -0,0 +1,17 @@
+--TEST--
+Don't optimize object -> iterable
+--FILE--
+<?php
+
+function test(object $arg): iterable {
+ return $arg;
+}
+test(new stdClass);
+
+?>
+--EXPECTF--
+Fatal error: Uncaught TypeError: Return value of test() must be iterable, object returned in %s:%d
+Stack trace:
+#0 %s(%d): test(Object(stdClass))
+#1 {main}
+ thrown in %s on line %d