Repository navigation
Conversation
bbrala
marked this pull request as ready for review
November 30, 2026 11:29
Author
|
Hmm, seems main is broken. Not gonna chase the CI right now |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Scope::getFunctionCallStack()andgetFunctionCallStackWithParameters()lose their frames inside a closure passed as an argument as soon as certain scope transitions happen.enterAnonymousFunction()andenterArrowFunction()hand the stack to the closure body, but the next??,isset(),empty(),if,try/finallyorforeachrebuilds the scope with[]and the stack is gone.Why it matters
Extensions use the stack to tell where they are. mglaman/phpstan-drupal's
DeprecationHelperScope(aDeprecatedScopeResolverfor phpstan-deprecation-rules) uses it to skip deprecations inside the$deprecatedCallableof Drupal'sDeprecationHelper::backwardsCompatibleCall():drupal-rector reads the same stack to avoid wrapping code twice and runs into the same problem. Real-world hits include search_api, which has five
$entity->original ?? NULLcalls inside such wrappers.Fix
There are twelve transitions that stay within the same function body but passed
[]for the stack. They now pass$this->inFunctionCallsStack:enterExpressionAssign()/exitExpressionAssign()setAllowedUndefinedExpression()/unsetAllowedUndefinedExpression()(??,isset(),empty())invalidateExpressionWithoutAliases()/invalidateMethodsOnExpression()scopeWith()calls inmergeWithVariableState()processFinallyScope(),processAlwaysIterableForeachScopeWithoutPollute(),generalizeWithVariableState()withRecordedStatementDelta()Transitions that start a new context still reset the stack: entering a file, namespace, class, trait or function. I didn't find anything in git history suggesting the
[]was deliberate. Most of these lines date from 17bde93, which only added theparentScopeargument after it, and the allowed-undefined pair was copied fromenterExpressionAssign()in 356250a.Left alone, and open to feedback:
enterClosureBind(),restoreOriginalScopeAfterClosureBind()andenterClosureCall()drop the stack too, along with the assigned/allowed-undefined expressions andparentScope. It looks like the same bug class, but I kept this PR to plain function bodies.enterAnonymousFunctionWithoutReflection()andenterArrowFunctionWithoutReflection()are only used byClosureTypeResolverfor inference walks, which don't run rules. The scope used for rules is rebuilt with the stack right after.getClosureScopeCacheKey()andClosureCallContextMatcherboth look at the stack. Keeping it consistent with the closure's position should only make them more accurate, and the full suite passes.Tests
ScopeFunctionCallStackInTransitionsRuleTestreports the stack at every method call and property fetch in a fixture. The fixture covers arrow functions and closures with??(left and right),isset()ternaries,empty(), assignments,if,try/finally,foreach, nested calls (trim(bar(fn () => ...))), and a control outside any call. Without thesrc/change, lines 31–37, 46, 56, 64, 68, 70 and 73 report an empty stack.Related, same area but a separate bug: #7011.
🤖 Generated with Claude Code
https://claude.ai/code/session_01EY2u2vs7fU42ARkw6JV7Na