Skip to content

Trigger deprecations when using "??" and "not" without explicit parentheses when precedence will change in 4.0#4367

Merged
fabpot merged 2 commits into
twigphp:3.xfrom
fabpot:NullCoalesceExpression-precedence
Oct 2, 2024
Merged

Trigger deprecations when using "??" and "not" without explicit parentheses when precedence will change in 4.0#4367
fabpot merged 2 commits into
twigphp:3.xfrom
fabpot:NullCoalesceExpression-precedence

Conversation

@fabpot

@fabpot fabpot commented Sep 30, 2024

Copy link
Copy Markdown
Contributor

Closes #3387
Closes #3642

@fabpot
fabpot force-pushed the NullCoalesceExpression-precedence branch from 385fe86 to afcfdee Compare September 30, 2024 14:44

@stof stof left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm wondering whether this could be implemented in the ExpressionParser while resolving precedence (by providing a future_precedence or something like that) instead of inspecting the AST after the fact. This could make it work in combination with third-party operators as well (which might have a precedence between the old and new ones and so be impacted).

{{ nope ?? nada ?? 'OK' }}
{{ 1 + nope ?? nada ?? 2 }}
{{ 1 + nope ?? 3 + nada ?? 2 }}
{{ nope ?? (nada ?? 'OK') }}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

should we really report this case ? It will be parsed the same in 4.0

Comment thread src/ExpressionParser.php Outdated
@fabpot
fabpot force-pushed the NullCoalesceExpression-precedence branch from afcfdee to 320751b Compare October 1, 2024 13:00
@fabpot

fabpot commented Oct 1, 2024

Copy link
Copy Markdown
Contributor Author

@stof I've rewritten how this all works. It's now all automated in the sense that it's done in a generic way where I just need the current and future precedence. It's a quick prototype I've done in a few minutes, so I might have forgotten something. Can you have a look?

@fabpot
fabpot force-pushed the NullCoalesceExpression-precedence branch 7 times, most recently from 9662b54 to b0249b6 Compare October 2, 2024 07:13
@fabpot fabpot changed the title Deprecate using ?? without explicit parentheses Deprecate using "??" and "not" without explicit parentheses Oct 2, 2024
@fabpot
fabpot force-pushed the NullCoalesceExpression-precedence branch from b0249b6 to 1acb004 Compare October 2, 2024 07:17
@fabpot fabpot changed the title Deprecate using "??" and "not" without explicit parentheses Trigger deprecations when using "??" and "not" without explicit parentheses when precedence will change in 4.0 Oct 2, 2024
@fabpot
fabpot force-pushed the NullCoalesceExpression-precedence branch from 1acb004 to 69e0b0f Compare October 2, 2024 07:19
@fabpot

fabpot commented Oct 2, 2024

Copy link
Copy Markdown
Contributor Author

The implementation is now much better. I'm done for this PR.

Comment thread src/Extension/CoreExtension.php Outdated
Comment thread src/ExpressionParser.php Outdated
@fabpot
fabpot force-pushed the NullCoalesceExpression-precedence branch from 69e0b0f to c726b99 Compare October 2, 2024 11:11
Comment thread src/Extension/CoreExtension.php Outdated
Comment thread src/Extension/ExtensionInterface.php Outdated
Comment thread src/ExpressionParser.php Outdated
@fabpot
fabpot force-pushed the NullCoalesceExpression-precedence branch from c726b99 to 877c055 Compare October 2, 2024 11:58
Comment thread CHANGELOG
* Deprecate using `~` with `+` or `-` in an expression without using parentheses to clarify precedence
* Deprecate using the `not` unary operator in an expression with ``*``, ``/``, ``//``, or ``%`` without using explicit parentheses to clarify precedence
* Deprecate using the `??` binary operator without explicit parentheses
* Deprecate using the `~` binary operator in an expression with `+` or `-` without using parentheses to clarify precedence

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this should also mention Add support for triggering deprecations for future operator precedence changes (and maybe this should have docymentation as well)

@fabpot
fabpot force-pushed the NullCoalesceExpression-precedence branch from 877c055 to 2081b1f Compare October 2, 2024 12:16
@fabpot
fabpot merged commit 247658c into twigphp:3.x Oct 2, 2024
@fabpot
fabpot deleted the NullCoalesceExpression-precedence branch October 2, 2024 12:17
fabpot added a commit that referenced this pull request Nov 20, 2024
This PR was merged into the 3.x branch.

Discussion
----------

Add missing import

Hi `@fabpot`, the phpdoc was updated in #4367 but the import was forgotten.
This leads to an error with all static analysis tools when implementing ExtensionInterface.

If possible a patch version would be helpful.

(Tests are already failing on 3.x)

Commits
-------

51d10ba Add missing import
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Wrong precedence of NOT operator Precedence of ?? operator

2 participants