75 lines
1.8 KiB
Diff
75 lines
1.8 KiB
Diff
|
From df2db7fceaff4f46909f1aa8b31f0a9010631fc9 Mon Sep 17 00:00:00 2001
|
||
|
From: Nikita Popov <nikita.ppv@gmail.com>
|
||
|
Date: Mon, 8 Jun 2020 11:31:28 +0200
|
||
|
Subject: [PATCH] Fixed bug #79657
|
||
|
|
||
|
Throwing an exception should count as an initialization for this
|
||
|
purpose.
|
||
|
---
|
||
|
NEWS | 2 ++
|
||
|
Zend/tests/bug79657.phpt | 42 ++++++++++++++++++++++++++++++++++++++++
|
||
|
Zend/zend_generators.c | 1 +
|
||
|
3 files changed, 45 insertions(+)
|
||
|
create mode 100644 Zend/tests/bug79657.phpt
|
||
|
|
||
|
diff --git a/Zend/tests/bug79657.phpt b/Zend/tests/bug79657.phpt
|
||
|
new file mode 100644
|
||
|
index 000000000000..fb2ccab3e3ef
|
||
|
--- /dev/null
|
||
|
+++ b/Zend/tests/bug79657.phpt
|
||
|
@@ -0,0 +1,42 @@
|
||
|
+--TEST--
|
||
|
+Bug #79657: "yield from" hangs when invalid value encountered
|
||
|
+--FILE--
|
||
|
+<?php
|
||
|
+
|
||
|
+function throwException(): iterable
|
||
|
+{
|
||
|
+ throw new Exception();
|
||
|
+}
|
||
|
+
|
||
|
+function loop(): iterable
|
||
|
+{
|
||
|
+ $callbacks = [
|
||
|
+ function () {
|
||
|
+ yield 'first';
|
||
|
+ },
|
||
|
+ function () {
|
||
|
+ yield from throwException();
|
||
|
+ }
|
||
|
+ ];
|
||
|
+
|
||
|
+ foreach ($callbacks as $callback) {
|
||
|
+ yield from $callback();
|
||
|
+ }
|
||
|
+}
|
||
|
+
|
||
|
+function get(string $first, int $second): array
|
||
|
+{
|
||
|
+ return [];
|
||
|
+}
|
||
|
+
|
||
|
+get(...loop());
|
||
|
+
|
||
|
+?>
|
||
|
+--EXPECTF--
|
||
|
+Fatal error: Uncaught Exception in %s:%d
|
||
|
+Stack trace:
|
||
|
+#0 %s(%d): throwException()
|
||
|
+#1 %s(%d): {closure}()
|
||
|
+#2 %s(%d): loop()
|
||
|
+#3 {main}
|
||
|
+ thrown in %s on line %d
|
||
|
diff --git a/Zend/zend_generators.c b/Zend/zend_generators.c
|
||
|
index 4cd9087303a3..15bbfca1c58a 100644
|
||
|
--- a/Zend/zend_generators.c
|
||
|
+++ b/Zend/zend_generators.c
|
||
|
@@ -857,6 +857,7 @@ ZEND_API void zend_generator_resume(zend_generator *orig_generator) /* {{{ */
|
||
|
} else {
|
||
|
generator = zend_generator_get_current(orig_generator);
|
||
|
zend_generator_throw_exception(generator, NULL);
|
||
|
+ orig_generator->flags &= ~ZEND_GENERATOR_DO_INIT;
|
||
|
goto try_again;
|
||
|
}
|
||
|
}
|