Skip to content

Fix GH-14874: report correct line for property/const variance errors - #21993

Open
iliaal wants to merge 1 commit into
php:masterfrom
iliaal:fix/gh-14874-property-const-variance-lineno
Open

iliaal wants to merge 1 commit into
php:masterfrom
iliaal:fix/gh-14874-property-const-variance-lineno

Conversation

@iliaal

@iliaal iliaal commented May 9, 2026

Copy link
Copy Markdown
Member

Fixes #14874. Adds a uint32_t line field to zend_property_info and zend_class_constant captured from the AST node, so the variance emitters route through zend_error_at_noreturn and point at the offending child member. Members left at line 0 (internal classes, trait-copied properties) fall back to the legacy emitter.

@jorgsowa

jorgsowa commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Can you add test case with trait from different file? Your fix may not work with it.

Example:

Zend/tests/type_declarations/gh14874_trait.inc:
<?php

trait T {
    public const int X = 1;
}

Zend/tests/type_declarations/gh14874_trait.phpt:
--TEST--
GH-14874 (Incorrect lineno for class const variance check with trait constant)
--FILE--
<?php

require __DIR__ . '/gh14874_trait.inc';

interface I {
    public const string X = '';
}

class C implements I {
    use T;
}
?>
--EXPECTF--
Fatal error: Type of C::X must be compatible with I::X of type string in %sgh14874_trait.php on line 9

Add a uint32_t line field to zend_property_info and zend_class_constant,
populated from the AST node lineno at compile time. The variance
emitters route through zend_error_at_noreturn so the error points at
the offending child member rather than the class declaration. Members
left at line 0 (internal classes, members copied from traits) fall back
to zend_error_noreturn (legacy behavior, no regression).

Fixes phpGH-14874
@iliaal
iliaal force-pushed the fix/gh-14874-property-const-variance-lineno branch from 4525613 to 5ce4bea Compare November 3, 2026 14:43
@iliaal

iliaal commented Nov 3, 2026

Copy link
Copy Markdown
Member Author

Ah, indeed: the copied constant kept the trait's line but took C's file, so it pointed at line 4 of the wrong file. Constants copied from traits now fall back to the old location, as trait properties already did, and I added your test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect lineno for property and class const variance check

2 participants