Skip to content

Remove XFAIL from sibling method call test #8482

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 22, 2022

Conversation

mvorisek
Copy link
Contributor

@mvorisek mvorisek commented May 2, 2022

I belive the XFAIL is not needed. Method defined in shared parent class MUST be accessible even if redeclared in sibling class.

@cmb69
Copy link
Member

cmb69 commented May 2, 2022

This isn't about calling a protected (static) method in the parent class, but rather in a sibling class:

  graph TD;
      A-->B1;
      A-->B2;
Loading

Should B2 be allowed to call protected (static) methods of B1? There was some discussion about this topic many years ago, but apparently, that lead nowhere.

@bwoebi
Copy link
Member

bwoebi commented May 2, 2022

I think, this being long-standing behaviour, we should reach consensus to not consider that a bug, but a feature.

As such, I support removing this XAFIL.

The justification for this behaviour should be that the sibling class' static should be considered an override in the parents scope (given that static methods are also subject to inheritance / LSP, they are guaranteed to be compatible).

I.e. a caller of the siblings function can know with certainty that a compatible Sibling::f() exists if the parent has a f() which he can see and thus should be allowed to rely on it and call it on the Sibling.

Basically, visibility does not hide things which are known to exist, but it decides whether things are known at all. Given that the parent already makes the function known, the visibility of the child is irrelevant.

@mvorisek mvorisek marked this pull request as draft May 2, 2022 13:18
@mvorisek mvorisek force-pushed the no_static_protected_method_xfail branch from b6b975c to 0b2b4fa Compare May 2, 2022 13:31
@mvorisek mvorisek changed the title Adjust static protected method test and remove XFAIL May 2, 2022
@mvorisek mvorisek marked this pull request as ready for review May 2, 2022 13:39
@cmb69
Copy link
Member

cmb69 commented May 2, 2022

@bwoebi, I tend to agree (and your reasoning basically matches Stas's).

@mvorisek mvorisek force-pushed the no_static_protected_method_xfail branch from 0b2b4fa to cf85aeb Compare May 2, 2022 13:50
@mvorisek
Copy link
Contributor Author

mvorisek commented May 2, 2022

@cmb69 yes :), I updated the title and improved the tests to test calls to sibling method /w and /wo definition in a parent class.

Yes, this is the only consistent way to satisfy LSP, if shared parent has some interface, the interface must be simply available.

@mvorisek mvorisek force-pushed the no_static_protected_method_xfail branch 2 times, most recently from 4e139c6 to 2c89995 Compare May 3, 2022 19:46
@ramsey
Copy link
Member

ramsey commented May 22, 2022

Is there a reason this targets PHP-8.0? Shouldn't it target master instead?

@mvorisek
Copy link
Contributor Author

Is there a reason this targets PHP-8.0? Shouldn't it target master instead?

it removes 2 XFAILs from PHP 8.0/8.1 CI and asserts the current behaviour as it is correct (explained/discussed above)

Copy link
Member

@nikic nikic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine for master. The tested behavior is consistent with prototype inheritance rules. (Our actual implementation is not entirely correct due to a bi-directional inheritance check, but this behavior is not being tested here.)

@mvorisek mvorisek changed the base branch from PHP-8.0 to master May 22, 2022 14:13
@mvorisek mvorisek force-pushed the no_static_protected_method_xfail branch from 2c89995 to ae5f1cd Compare May 22, 2022 14:16
@ramsey ramsey added this to the PHP 8.2 milestone May 22, 2022
@nikic nikic merged commit dfb68fe into php:master May 22, 2022
@mvorisek mvorisek deleted the no_static_protected_method_xfail branch May 22, 2022 19:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
5 participants