PHP 8.4 Support: Asymmetric Visibility v2#8177
Conversation
- apache#8035 - https://wiki.php.net/rfc#php_84 - https://wiki.php.net/rfc/asymmetric-visibility-v2 - https://www.php.net/manual/en/language.oop5.final.php - Fix the lexers and the parser(grammar file) - Support for the `final` field(property) - Don't handle modifier errors for methods, constants, and fields in the parser. Instead, handle them in the hint error. Writing all valid cases for each member is very hard and complicated because the current PHP has many modifiers. - Fix the `PHP84UnhandledError` - Add/Fix unit tests for the navigator, lexer, and parser Example: ```php class AsymmetricVisibilityClass { // Constructor Property Promotion public function __construct( public(set) string $field1, // implicit public public private(set) int $field2, public protected(set) readonly int $field3, ) {} // valid fields public(set) string $example1; // implicit public public private(set) int $example2 = 1; public protected(set) readonly int $example3; final private private(set) readonly string|int $example4; // final is available as of PHP 8.4 // invalid cases but the parser doesn't handle them as errors // e.g. public public string $invalid1 = "invalid"; // multiple same modifiers final private private(set) string|int $invalid2; // cannot use both final and private public public(set) $invalid3; // need type private public(set) string $invalid4; // visibility(private) must not be weaker than set visibility } ```
php/php.editor/src/org/netbeans/modules/php/editor/completion/CompletionContextFinder.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Moved to ModifiersCheckHintError.
There was a problem hiding this comment.
Show errors here because the parser allows invalid modifier combinations.
| ; | ||
|
|
||
| variable_modifiers ::= | ||
| ppp_modifiers:modifier | ||
| non_empty_member_modifiers:modifier |
There was a problem hiding this comment.
The parser allows valid combinations so far. However, it's possible to maintain it no longer...because there are many modifiers.
So, the parser allows invalid combinations now.
Instead, errors are handled via ModifiersCheckHintError.
| @@ -2493,6 +2505,92 @@ optional_property_modifiers ::= | |||
| result |= pModifier.intValue(); | |||
| RESULT = Integer.valueOf(result); | |||
| :} | |||
|
|
|||
| | ppp_modifiers:pppModifier ppp_set_modifiers:pppSetModifier | |||
There was a problem hiding this comment.
Probably, we can change here to non_empty_member_modifiers in the future.
|
@tmysik Could you please have a look at each commit? I've added unit tests as far as possible. So, changed files are so many. Sorry for that... |
php/php.editor/src/org/netbeans/modules/php/editor/completion/CompletionContextFinder.java
Outdated
Show resolved
Hide resolved
tmysik
left a comment
There was a problem hiding this comment.
I did a quick review, a lot of work done by @junichi11 👏
- apache#8035 - https://wiki.php.net/rfc#php_84 - https://wiki.php.net/rfc/asymmetric-visibility-v2 - https://www.php.net/manual/en/language.oop5.final.php - Fix `ModifiersCheckHintError` - Move final modifier errors from the `FinalModifierHintError` to `ModifiersCheckHintError` - Add useful methods to the `PhpVersion` - `hasFinalConst()` - `hasDeprecatedAttribute()` - `hasFinalField()` - `hasAsymmetricVisibility()` - Add methods and constants for set visibility to the `PhpModifiers` - Add unit tests for hints - Change `javac.source=1.8` to `javac.release=17` - Increment spec vesions
- apache#8035 - https://wiki.php.net/rfc#php_84 - https://wiki.php.net/rfc/asymmetric-visibility-v2 - Fix hints - `IncorrectConstructorPropertyPromotionHintError` - `UnusedVariableHint` - Add/Fix unit tests
- apache#8035 - https://wiki.php.net/rfc#php_84 - https://wiki.php.net/rfc/asymmetric-visibility-v2 - Fix Code Completion - Fix/Add unit tests Note: CC does not work correctly on the following caret position because set visibility keywords contain a brace. ```php class Example { public private(se^ // ^: caret } ```
- apache#8035 - https://wiki.php.net/rfc#php_84 - https://wiki.php.net/rfc/asymmetric-visibility-v2 - Add unit tests for formatter - set visibility (`private(set) int $i;`) - final property (`final public string $s = "string";`)
b024e57 to
da5c988
Compare
|
@tmysik Thank you for your time, Tomas! |
|
@junichi11 nothing to thank for, really. You did all the job. |
PHP 8.4 Support: Asymmetric Visibility v2 (Part 1)
finalfield(property)Writing all valid cases for each member is very hard and complicated because the current PHP has many modifiers.
PHP84UnhandledErrorExample:
PHP 8.4
PHP 8.3
Navigator
PHP 8.4 Support: Asymmetric Visibility v2 (Part 2)
ModifiersCheckHintErrorFinalModifierHintErrortoModifiersCheckHintErrorPhpVersionhasFinalConst()hasDeprecatedAttribute()hasFinalField()hasAsymmetricVisibility()PhpModifiersPHP 8.4 Support: Asymmetric Visibility v2 (Part 3)
IncorrectConstructorPropertyPromotionHintErrorUnusedVariableHintPHP 8.4 Support: Asymmetric Visibility v2 (Part 4)
Note: CC does not work correctly on the following caret position because set visibility keywords contain a brace.
PHP 8.4 Support: Asymmetric Visibility v2 (Part 5)
private(set) int $i;)final public string $s = "string";)