From: Nikita Popov Date: Mon, 22 Sep 2014 22:57:00 +0000 (+0200) Subject: Test a few more error conditions in the compiler X-Git-Tag: PRE_NATIVE_TLS_MERGE~158^2~57 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=75533c9b2343824c73a53a9800d282e6bec446da;p=php Test a few more error conditions in the compiler --- diff --git a/Zend/tests/class_name_as_scalar_error_007.phpt b/Zend/tests/class_name_as_scalar_error_007.phpt new file mode 100644 index 0000000000..2bfa5f38f8 --- /dev/null +++ b/Zend/tests/class_name_as_scalar_error_007.phpt @@ -0,0 +1,10 @@ +--TEST-- +Cannot access self::class when no class scope is active +--FILE-- + +--EXPECTF-- +Fatal error: Cannot access self::class when no class scope is active in %s on line %d diff --git a/Zend/tests/duplicate_label_error.phpt b/Zend/tests/duplicate_label_error.phpt new file mode 100644 index 0000000000..c89d7a6991 --- /dev/null +++ b/Zend/tests/duplicate_label_error.phpt @@ -0,0 +1,12 @@ +--TEST-- +Duplicate labels are not allowed +--FILE-- + +--EXPECTF-- +Fatal error: Label 'foo' already defined in %s on line %d diff --git a/Zend/tests/magic_const_in_global_scope.phpt b/Zend/tests/magic_const_in_global_scope.phpt new file mode 100644 index 0000000000..31f7eae6d7 --- /dev/null +++ b/Zend/tests/magic_const_in_global_scope.phpt @@ -0,0 +1,26 @@ +--TEST-- +Test use of magic constants in the global scope +--FILE-- + +--EXPECTF-- +int(4) +string(%d) "%s" +string(%d) "%s" +string(0) "" +string(0) "" +string(0) "" +string(0) "" +string(0) "" diff --git a/Zend/tests/special_name_error1.phpt b/Zend/tests/special_name_error1.phpt new file mode 100644 index 0000000000..63bf5a63fd --- /dev/null +++ b/Zend/tests/special_name_error1.phpt @@ -0,0 +1,10 @@ +--TEST-- +Cannot use special class name as namespace +--FILE-- + +--EXPECTF-- +Fatal error: Cannot use 'self' as namespace name in %s on line %d diff --git a/Zend/tests/special_name_error2.phpt b/Zend/tests/special_name_error2.phpt new file mode 100644 index 0000000000..08122b3249 --- /dev/null +++ b/Zend/tests/special_name_error2.phpt @@ -0,0 +1,10 @@ +--TEST-- +Cannot use special class name as alias +--FILE-- + +--EXPECTF-- +Fatal error: Cannot use Foo\Bar as self because 'self' is a special class name in %s on line %d diff --git a/Zend/tests/special_name_error3.phpt b/Zend/tests/special_name_error3.phpt new file mode 100644 index 0000000000..74e69f1938 --- /dev/null +++ b/Zend/tests/special_name_error3.phpt @@ -0,0 +1,10 @@ +--TEST-- +Cannot use special class name as trait name +--FILE-- + +--EXPECTF-- +Fatal error: Cannot use 'self' as class name as it is reserved in %s on line %d diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index ca4aa695ad..262dc8c188 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -3256,11 +3256,9 @@ void zend_compile_goto(zend_ast *ast TSRMLS_DC) /* {{{ */ void zend_compile_label(zend_ast *ast TSRMLS_DC) /* {{{ */ { - zval *label = zend_ast_get_zval(ast->child[0]); + zend_string *label = zend_ast_get_str(ast->child[0]); zend_label dest; - ZEND_ASSERT(Z_TYPE_P(label) == IS_STRING); - if (!CG(context).labels) { ALLOC_HASHTABLE(CG(context).labels); zend_hash_init(CG(context).labels, 8, NULL, ptr_dtor, 0); @@ -3269,8 +3267,8 @@ void zend_compile_label(zend_ast *ast TSRMLS_DC) /* {{{ */ dest.brk_cont = CG(context).current_brk_cont; dest.opline_num = get_next_op_number(CG(active_op_array)); - if (!zend_hash_add_mem(CG(context).labels, Z_STR_P(label), &dest, sizeof(zend_label))) { - zend_error_noreturn(E_COMPILE_ERROR, "Label '%s' already defined", Z_STRVAL_P(label)); + if (!zend_hash_add_mem(CG(context).labels, label, &dest, sizeof(zend_label))) { + zend_error_noreturn(E_COMPILE_ERROR, "Label '%s' already defined", label->val); } } /* }}} */