Use consistent line numbers for early binding errors

Non-early-bound classes report inheritance errors at the first line
of the class, if no better line information is available (we should
really store line numbers for properties at least...) Early bound
classes report it at the last line of the class instead.

Make the error reporting consistent by always reporting at the
first line.
This commit is contained in:
Nikita Popov 2021-07-28 12:35:20 +02:00
parent f78216f62e
commit 380e705fc2
26 changed files with 25 additions and 37 deletions

View file

@ -11,4 +11,4 @@ class Bar extends Foo {
}
?>
--EXPECTF--
Fatal error: Type of Bar::$qux must be int (as in class Foo) in %s on line 8
Fatal error: Type of Bar::$qux must be int (as in class Foo) in %s on line 6

View file

@ -14,4 +14,4 @@ class Bar extends Foo {
}
?>
--EXPECTF--
Fatal error: Type of Bar::$qux must be Whatever (as in class Foo) in %s on line 11
Fatal error: Type of Bar::$qux must be Whatever (as in class Foo) in %s on line 9

View file

@ -11,4 +11,4 @@ class Bar extends Foo {
}
?>
--EXPECTF--
Fatal error: Type of Bar::$qux must be int (as in class Foo) in %s on line 8
Fatal error: Type of Bar::$qux must be int (as in class Foo) in %s on line 6

View file

@ -11,4 +11,4 @@ class Baz extends Foo{
}
?>
--EXPECTF--
Fatal error: Type of Baz::$bar must not be defined (as in class Foo) in %s on line 8
Fatal error: Type of Baz::$bar must not be defined (as in class Foo) in %s on line 6

View file

@ -7761,13 +7761,10 @@ void zend_compile_class_decl(znode *result, zend_ast *ast, bool toplevel) /* {{{
&& ((parent_ce->type != ZEND_INTERNAL_CLASS) || !(CG(compiler_options) & ZEND_COMPILE_IGNORE_INTERNAL_CLASSES))
&& ((parent_ce->type != ZEND_USER_CLASS) || !(CG(compiler_options) & ZEND_COMPILE_IGNORE_OTHER_FILES) || (parent_ce->info.user.filename == ce->info.user.filename))) {
CG(zend_lineno) = decl->end_lineno;
if (zend_try_early_bind(ce, parent_ce, lcname, NULL)) {
CG(zend_lineno) = ast->lineno;
zend_string_release(lcname);
return;
}
CG(zend_lineno) = ast->lineno;
}
} else if (EXPECTED(zend_hash_add_ptr(CG(class_table), lcname, ce) != NULL)) {
zend_string_release(lcname);

View file

@ -3983,16 +3983,7 @@ static void preload_link(void)
/* Set filename & lineno information for inheritance errors */
CG(in_compilation) = 1;
CG(compiled_filename) = ce->info.user.filename;
if (ce->parent_name
&& !ce->num_interfaces
&& !ce->num_traits
&& (parent->type == ZEND_INTERNAL_CLASS
|| parent->info.user.filename == ce->info.user.filename)) {
/* simulate early binding */
CG(zend_lineno) = ce->info.user.line_end;
} else {
CG(zend_lineno) = ce->info.user.line_start;
}
ce = zend_do_link_class(ce, NULL, key);
if (!ce) {
ZEND_ASSERT(0 && "Class linking failed?");

View file

@ -12,4 +12,4 @@ class B extends A {
}
?>
--EXPECTF--
Fatal error: Access level to B::publicConst must be public (as in class A) in %s on line 9
Fatal error: Access level to B::publicConst must be public (as in class A) in %s on line 7

View file

@ -12,4 +12,4 @@ class B extends A {
}
?>
--EXPECTF--
Fatal error: Access level to B::protectedConst must be protected (as in class A) or weaker in %s on line 9
Fatal error: Access level to B::protectedConst must be protected (as in class A) or weaker in %s on line 7

View file

@ -28,4 +28,4 @@ Redeclare inherited protected static property as private.
$b->showB();
?>
--EXPECTF--
Fatal error: Cannot redeclare static A::$p as non static B::$p in %s on line 18
Fatal error: Cannot redeclare static A::$p as non static B::$p in %s on line 11

View file

@ -27,4 +27,4 @@ Redeclare inherited protected static property as private static.
B::showB();
?>
--EXPECTF--
Fatal error: Access level to B::$p must be protected (as in class A) or weaker in %s on line 18
Fatal error: Access level to B::$p must be protected (as in class A) or weaker in %s on line 11

View file

@ -28,4 +28,4 @@ Redeclare inherited protected static property as protected.
$b->showB();
?>
--EXPECTF--
Fatal error: Cannot redeclare static A::$p as non static B::$p in %s on line 18
Fatal error: Cannot redeclare static A::$p as non static B::$p in %s on line 11

View file

@ -28,4 +28,4 @@ Redeclare inherited protected static property as public.
$b->showB();
?>
--EXPECTF--
Fatal error: Cannot redeclare static A::$p as non static B::$p in %s on line 18
Fatal error: Cannot redeclare static A::$p as non static B::$p in %s on line 11

View file

@ -29,4 +29,4 @@ Redeclare inherited protected property as private (duplicates Zend/tests/errmsg_
$b->showB();
?>
--EXPECTF--
Fatal error: Access level to B::$p must be protected (as in class A) or weaker in %s on line 18
Fatal error: Access level to B::$p must be protected (as in class A) or weaker in %s on line 11

View file

@ -29,4 +29,4 @@ Redeclare inherited protected property as private static.
B::showB();
?>
--EXPECTF--
Fatal error: Cannot redeclare non static A::$p as static B::$p in %s on line 18
Fatal error: Cannot redeclare non static A::$p as static B::$p in %s on line 11

View file

@ -29,4 +29,4 @@ Redeclare inherited protected property as protected static.
B::showB();
?>
--EXPECTF--
Fatal error: Cannot redeclare non static A::$p as static B::$p in %s on line 18
Fatal error: Cannot redeclare non static A::$p as static B::$p in %s on line 11

View file

@ -29,4 +29,4 @@ Redeclare inherited protected property as public static.
B::showB();
?>
--EXPECTF--
Fatal error: Cannot redeclare non static A::$p as static B::$p in %s on line 18
Fatal error: Cannot redeclare non static A::$p as static B::$p in %s on line 11

View file

@ -28,4 +28,4 @@ Redeclare inherited public static property as private.
$b->showB();
?>
--EXPECTF--
Fatal error: Cannot redeclare static A::$p as non static B::$p in %s on line 18
Fatal error: Cannot redeclare static A::$p as non static B::$p in %s on line 11

View file

@ -27,4 +27,4 @@ Redeclare inherited public static property as private static.
B::showB();
?>
--EXPECTF--
Fatal error: Access level to B::$p must be public (as in class A) in %s on line 18
Fatal error: Access level to B::$p must be public (as in class A) in %s on line 11

View file

@ -28,4 +28,4 @@ Redeclare inherited public static property as protected.
$b->showB();
?>
--EXPECTF--
Fatal error: Cannot redeclare static A::$p as non static B::$p in %s on line 18
Fatal error: Cannot redeclare static A::$p as non static B::$p in %s on line 11

View file

@ -27,4 +27,4 @@ Redeclare inherited public static property as protected static.
B::showB();
?>
--EXPECTF--
Fatal error: Access level to B::$p must be public (as in class A) in %s on line 18
Fatal error: Access level to B::$p must be public (as in class A) in %s on line 11

View file

@ -28,4 +28,4 @@ Redeclare inherited public static property as public.
$b->showB();
?>
--EXPECTF--
Fatal error: Cannot redeclare static A::$p as non static B::$p in %s on line 18
Fatal error: Cannot redeclare static A::$p as non static B::$p in %s on line 11

View file

@ -29,4 +29,4 @@ Redeclare inherited public property as private.
$b->showB();
?>
--EXPECTF--
Fatal error: Access level to B::$p must be public (as in class A) in %s on line 18
Fatal error: Access level to B::$p must be public (as in class A) in %s on line 11

View file

@ -29,4 +29,4 @@ Redeclare inherited public property as private static.
B::showB();
?>
--EXPECTF--
Fatal error: Cannot redeclare non static A::$p as static B::$p in %s on line 18
Fatal error: Cannot redeclare non static A::$p as static B::$p in %s on line 11

View file

@ -29,4 +29,4 @@ Redeclare inherited public property as protected.
$b->showB();
?>
--EXPECTF--
Fatal error: Access level to B::$p must be public (as in class A) in %s on line 18
Fatal error: Access level to B::$p must be public (as in class A) in %s on line 11

View file

@ -29,4 +29,4 @@ Redeclare inherited public property as protected static.
B::showB();
?>
--EXPECTF--
Fatal error: Cannot redeclare non static A::$p as static B::$p in %s on line 18
Fatal error: Cannot redeclare non static A::$p as static B::$p in %s on line 11

View file

@ -29,4 +29,4 @@ Redeclare inherited public property as public static.
B::showB();
?>
--EXPECTF--
Fatal error: Cannot redeclare non static A::$p as static B::$p in %s on line 18
Fatal error: Cannot redeclare non static A::$p as static B::$p in %s on line 11