diff options
author | Nikita Popov <nikita.ppv@gmail.com> | 2021-01-25 16:17:14 +0100 |
---|---|---|
committer | Nikita Popov <nikita.ppv@gmail.com> | 2021-01-25 16:17:50 +0100 |
commit | 18507853cb727361ea09fca8a7e4458b9262b145 (patch) | |
tree | 2eb814e653df0b4933ec0338ff1a712cbe7d508c /Zend/zend_compile.c | |
parent | d319098b24342e9a4e2344dc7f588b74edcaa846 (diff) | |
download | php-git-18507853cb727361ea09fca8a7e4458b9262b145.tar.gz |
Improve switch continue warning
Don't suggest "continue N+1" if there is no wrapping loop. The
resulting code would be illegal.
Diffstat (limited to 'Zend/zend_compile.c')
-rw-r--r-- | Zend/zend_compile.c | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index e7f2b0b04a..57c33e3c96 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -4891,15 +4891,26 @@ void zend_compile_break_continue(zend_ast *ast) /* {{{ */ if (CG(context).brk_cont_array[cur].is_switch) { if (depth == 1) { - zend_error(E_WARNING, - "\"continue\" targeting switch is equivalent to \"break\". " \ - "Did you mean to use \"continue " ZEND_LONG_FMT "\"?", - depth + 1); + if (CG(context).brk_cont_array[cur].parent == -1) { + zend_error(E_WARNING, + "\"continue\" targeting switch is equivalent to \"break\""); + } else { + zend_error(E_WARNING, + "\"continue\" targeting switch is equivalent to \"break\". " \ + "Did you mean to use \"continue " ZEND_LONG_FMT "\"?", + depth + 1); + } } else { - zend_error(E_WARNING, - "\"continue " ZEND_LONG_FMT "\" targeting switch is equivalent to \"break " ZEND_LONG_FMT "\". " \ - "Did you mean to use \"continue " ZEND_LONG_FMT "\"?", - depth, depth, depth + 1); + if (CG(context).brk_cont_array[cur].parent == -1) { + zend_error(E_WARNING, + "\"continue " ZEND_LONG_FMT "\" targeting switch is equivalent to \"break " ZEND_LONG_FMT "\"", + depth, depth); + } else { + zend_error(E_WARNING, + "\"continue " ZEND_LONG_FMT "\" targeting switch is equivalent to \"break " ZEND_LONG_FMT "\". " \ + "Did you mean to use \"continue " ZEND_LONG_FMT "\"?", + depth, depth, depth + 1); + } } } } |